0

onMeasure()オーバーライドされたものだけを使用してカスタムビューを定義しました。

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    setMeasuredDimension((int)(iwidth * cellWidth), (int)(iheight * cellHeight));
}

使用される変数は、という名前の1つのセッターによって設定されるクラスメンバーsetStep()です。

ボタンで変更します:

button.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            float step = hidingPanel.getStep();

            step += stepstep;

            hidingPanel.setStep(step);
            hidingPanel.invalidate();

            setTextButton();
        }

    });

レイアウトは以下の通りです

<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>

HidingPanel私のカスタムビューはどこにありますか。

ボタンを押すとビューが大きくなると思っていましたが、大きくなりません。ディメンションがゼロの場合、onMeasure()が最初に呼び出されるのは数回だけであることがわかりました。ボタンをクリックして、後で測定を促進する方法は?

4

1 に答える 1

1

requestLayout(); を呼び出す必要があります。ビューの親で。

于 2012-05-17T19:21:26.653 に答える