带有图像和文本的 Android ImageButton

标签 android image text button imagebutton

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

有什么想法吗?

谢谢 克里斯

最佳答案

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

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

关于带有图像和文本的 Android ImageButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3226206/

相关文章:

c# - 如何在 C# 中将字节数组转换为图像?

java - 保存到内存 Android

CSS 动画 - 颜色改变后改变背景图像

python - 自动调整文本小部件的高度以适应所有文本

c# - 文本渲染器 : How to measure text as if it was on machine with different Dpi?

android - 在应用程序外部显示模态消息并在一段时间后自行关闭

android - 不带滚动条的 ListView 在 ScrollView 中使用

c++ - 使用 FreeType/GLFW 根本不呈现文本

android - android 中的 SurfaceView 刷新

java - EditText .setError() 未在重新创建时应用我的自定义错误图标