上に画像、下にテキストがあるボタンが欲しいのですが。画像とテキストの両方が実行時に決定されるので、ボタンごとにImageButtonのsetImageBitmapとButtonのsetTextを組み合わせることができるようにしたいと思います。
何か案は?
ありがとうクリス
上に画像、下にテキストがあるボタンが欲しいのですが。画像とテキストの両方が実行時に決定されるので、ボタンごとにImageButtonのsetImageBitmapとButtonのsetTextを組み合わせることができるようにしたいと思います。
何か案は?
ありがとうクリス
画像ボタンとテキストの両方を囲む....でコードを表示して、画像ボタンの背景のテキストを上書きします。すなわち:
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="69dp"
android:layout_marginTop="96dp"
android:background="@drawable/icon"
android:scaleType="fitXY" />
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Droid"
android:textColor="#ff0000"
android:textSize="24dip" >
</TextView>
</FrameLayout>
私はついに私が探していたものを見つけました:
setCompoundDrawablesWithIntrinsicBoundsを使用すると、ボタンにビットマップ/ドローアブルを割り当てると同時に、setTextを使用できます。
例:ボタンの上にビットマップ画像を設定するには、次のようにします。
button.setCompoundDrawablesWithIntrinsicBounds(null、new BitmapDrawable(bitmapimage)、null、null);
それを行う簡単な方法はないと思います。
カスタムコンポーネントを作成します。