プログラムで ViewFlipper の重みを変更したいと思います。2 つの列がある TableRow があります。2 番目の列に ViewFlipper が含まれている場合、1 番目の列には RelativeLayout 要素が含まれます。私の ViewFlipper には 2 つのビューが含まれています。Java コードで、ボタンをクリックしたときに ViewFlipper の表示ビューを変更します。私がやりたいことは、(showNext() を呼び出して) ViewFlipper ビューを変更するときに、ViewFlipper の重みを変更して画面内で大きくできるようにすることです。
つまり、行の最初の列の重みは 1 で、2 番目の列 (ViewFlipper) の重みは 0.8 です。ボタンをクリックすると、それらの重みをプログラムで変更したいと思います。それは可能ですか?どのように ?以下は私のXMLコードです。
Webで検索したところ、次の解決策が見つかりました。
myFlipper.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, 0.3f));
これは機能しません。クラッシュします。ViewFlipper は LinearLayout ではないため、これは正常だと思います。
ここに私のXMLコードがあります:
<TableRow
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#00000000" >
<RelativeLayout
android:id="@+id/rltest"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_centerInParent="true"
android:paddingLeft="6px"
android:paddingRight="6px"
android:background="#00000000" >
<TextView
android:id="@+id/tvtest"
android:layout_width="match_parent"
android:layout_height="60px"
android:layout_alignParentLeft="true"
android:textColor="#FFFFFF"
android:textSize="22px"
android:singleLine="true"
android:background="#00000000"
android:gravity="center_vertical" />
</RelativeLayout>
<ViewFlipper
android:id="@+id/flipper"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="0.8"
android:background="#00000000" >
<TextView
android:id="@+id/tvName"
android:layout_width="wrap_content"
android:layout_height="60px" />
<LinearLayout
android:id="@+id/lltest"
android:layout_width="match_parent"
android:layout_height="60px"
android:layout_centerInParent="true"
android:background="#00000000"
android:gravity="center" />
</ViewFlipper>
</TableRow>
何か考えはありますか?
ありがとう