I’m dynamically modifying height of the button based on seekbar progress.
Now I want to retreive height of the button. So I used btn1.getHeight() in onProgressChanged() method of SeekBar.
But it gives incorrect/old set of values for button height.
Instead, if I used btn1.getHeight() in onStopTrackingTouch(), I’m getting correct values.
This simply means , when I try to retreive height of the button in onProgressChanged() , UI changes are visible on screen but yet not registered wchich results into getting incorrect/old values.
How to get correct values in onProgressChanged() ?
Is there other way round to do this? Any help appreciated.
Edit
@Luksprog : I made following changes :
<SeekBar
android:id="@+id/seekBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:maxHeight="9dp"
android:minHeight="9dp"
android:padding="10dp"
android:max="100"
android:progressDrawable="@drawable/seekbar_progress"
android:thumb="@drawable/shine_btn" />
<RelativeLayout
android:id="@+id/Graph01"
android:layout_width="wrap_content"
android:layout_height="200dp"
android:layout_below="@id/seekBar"
android:layout_marginTop="50dp"
android:gravity="bottom" >
<Button
android:id="@+id/btnGraph01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#99f" />
<com.example.calci.views.MyTextView
android:id="@+id/tvGraph01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/btnGraph01" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/Graph02"
android:layout_width="wrap_content"
android:layout_height="200dp"
android:layout_below="@id/seekBar"
android:layout_toRightOf="@id/Graph01"
android:layout_marginTop="50dp"
android:gravity="bottom" >
<Button
android:id="@+id/btnGraph02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#99f" />
<com.example.calci.views.MyTextView
android:id="@+id/tvGraph02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/btnGraph02" />
</RelativeLayout>
</RelativeLayout>
and in activity
RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(20,
2 * progress * 1);
lp2.setMargins(55, 0, 0, 0);
btnGraph01.setLayoutParams(lp2);
RelativeLayout.LayoutParams lp3 = new RelativeLayout.LayoutParams(
new ViewGroup.MarginLayoutParams(20,
RelativeLayout.LayoutParams.WRAP_CONTENT));
lp3.setMargins(55, 0, 0, 30);
tvGraph01.setLayoutParams(lp3);
tvGraph01.setTextSize(6);
tvGraph01.setGravity(Gravity.CENTER);
But TextView is getting displayed inside button… Why it is so?
PLEASE CORRECT ME IF I”M WRONG…
First I’m guessing this is related to your previous question. I wouldn’t use
weights, instead I would simply use aRelativeLayoutwith theButtonsattached to the bottom, this way theButtonswill increase in height upwards. Like this:Second, I don’t see why you can’t get the desired height. With my code above by using
button.getHeight()you’ll get the previous height store(as the new height will not be stored until you get out ofonProgressChanged). But this shouldn’t stop you from getting the new height because you are actually calculating that value yourself with :Code:
Edit:
Your layout file is wrong:
Now in code there is no need to modify the
LayoutParamsoftvGraph01, it will follow theButtonas it grows/shrinks, also get the currentLayoutParamsof theButtonand modify it instead of creating new ones again and again: