I have a Button within LinearLayout and I want to retreive it’s height.
I used sample_button.getHeight(), but it gives different valus of height.
i.e. I’m modifying height of the button based on seekbar progress as following :
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromTouch) {
LinearLayout.LayoutParams lp2 = new LinearLayout.LayoutParams(
new ViewGroup.MarginLayoutParams(50, progress * 20));
lp2.setMargins(200, 0, 0, 0);
sample_button.setLayoutParams(lp2);
Log.i("Activity", "progress = " + progress);
Log.i("Activity",
"sample_button.getHeight() = " + sample_button.getHeight());
}
and the log values are as following:
progress = 1
sample_button.getHeight() = 60
progress = 2
sample_button.getHeight() = 20
progress = 3
sample_button.getHeight() = 40
progress = 2
sample_button.getHeight() = 60
progress = 3
sample_button.getHeight() = 40
progress = 4
sample_button.getHeight() = 60
progress = 3
sample_button.getHeight() = 80
Note that button is getting displayed properly but when progress=2 , it shows height=20 first but then it shows height=60 and so on for other progress value as shown above.
Am I doing anything wrong. Any help appreciated.
Have you tried it this way: