I have defined my custom view with the only onMeasure() overridden:
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
setMeasuredDimension((int)(iwidth * cellWidth), (int)(iheight * cellHeight));
}
used variables are class members which are set by one single setter named setStep().
I change it with button:
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
float step = hidingPanel.getStep();
step += stepstep;
hidingPanel.setStep(step);
hidingPanel.invalidate();
setTextButton();
}
});
The layout is following
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<com.inthemoon.incubation.HidingPanel
android:id="@+id/hidingPanel"
android:background="@android:color/darker_gray"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_marginTop="0dp"
android:layout_marginLeft="0dp"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:background="@android:color/black"
>
<Button
android:id="@+id/button"
android:layout_width="200dp"
android:layout_height="100dp"
/>
</LinearLayout>
</RelativeLayout>
where HidingPanel is my custom view.
I was expecting that my view will grow on button press but it doesn’t. I found that onMeasure() is called only few times at the beginning, when dimensions are zero. How to promote measuring later, on button click?
You need to call requestLayout(); on the parent of the View.