Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Seekbar not setting .getLayoutParams().height

I have a Seekbar that works perfectly except for one part. I want to adjust the height of a textView depending on the Seekbar value.

I'm using this code to adjust the height of the textView:

SeekBar sb1 = (SeekBar)findViewById(R.id.telecom_years_bar);
    sb1.setMax(14);
    sb1.setProgress(9);
    sb1.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener(){

        @Override
        public void onProgressChanged(SeekBar sb1, int progress, boolean fromUser) {
            progress = progress + 1;
            TextView RedInitialBar = (TextView) findViewById(R.id.initial_bar1);
            RedInitialBar.getLayoutParams().height = (progress);

I have similar code on create and it works fine when the activity first loads, but adjusting the Seekbar doesn't update the height of the textView. All of the other calculations I have tied to that Seekbar recalculate perfectly when it is adjusted. What am I missing?

like image 603
DeadSilentFilmStars Avatar asked Jun 25 '26 23:06

DeadSilentFilmStars


1 Answers

When you change the height or any dimensions of a View after it's been laid out onto the screen, it must be laid out again. Try calling requestLayout() on the TextView.

like image 179
Alex Fu Avatar answered Jun 28 '26 11:06

Alex Fu