3

上に画像、下にテキストがあるボタンが欲しいのですが。画像とテキストの両方が実行時に決定されるので、ボタンごとにImageButtonのsetImageBitmapとButtonのsetTextを組み合わせることができるようにしたいと思います。

何か案は?

ありがとうクリス

4

4 に答える 4

3

画像ボタンとテキストの両方を囲む....でコードを表示して、画像ボタンの背景のテキストを上書きします。すなわち:

 <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>
于 2012-03-30T11:19:11.170 に答える
2

私はついに私が探していたものを見つけました:

setCompoundDrawablesWithIntrinsicBoundsを使用すると、ボタンにビットマップ/ドローアブルを割り当てると同時に、setTextを使用できます。

于 2010-07-13T05:46:00.470 に答える
1

例:ボタンの上にビットマップ画像を設定するには、次のようにします。

button.setCompoundDrawablesWithIntrinsicBounds(null、new BitmapDrawable(bitmapimage)、null、null);

于 2010-07-15T07:17:52.817 に答える
0

それを行う簡単な方法はないと思います。

カスタムコンポーネントを作成します。

于 2010-07-12T06:34:32.467 に答える