3

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?

2 Answers2

2

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.

Alex Fu
  • 5,509
  • 3
  • 31
  • 40
  • Of course! I just added 'RedInitialBar.requestLayout();' before 'RedInitialBar.getLayoutParams().height = (progress);' and it seems to work perfectly. Thanks a million! – DeadSilentFilmStars Jul 23 '13 at 13:35
0

Yes, setting TextView height will act no effect. Instead of it use

RedInitialBar.setText( size * density );
Sergey Brazhnik
  • 661
  • 4
  • 13
  • Thanks for the answer, but does this adjust the size of the text/font or the size of the textView box? Because I only want to adjust the height of the textView box. My code above works perfectly at first (after 'onCreate') doesn't work together with the seekbar. – DeadSilentFilmStars Jul 23 '13 at 13:00