3

我想要一个顶部有图像,底部有一些文字的按钮。图像和文本都是在运行时决定的,所以我希望能够为每个按钮组合 ImageButton 的 setImageBitmap 和 Button 的 setText。

有任何想法吗?

谢谢克里斯

4

4 回答 4

3

将图像按钮和文本视图代码都包围在 .... 中以覆盖图像按钮背景上的文本。IE:

 <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

我不认为有一个简单的方法可以做到这一点。

我会创建一个custom-component

于 2010-07-12T06:34:32.467 回答