首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Android:将文本放在按钮下

Android:将文本放在按钮下
EN

Stack Overflow用户
提问于 2016-04-13 08:42:41
回答 4查看 1.3K关注 0票数 1

我试着把文字放在图像下,但文字在图像上已经过时了。

代码语言:javascript
运行
复制
<Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/snap"
        android:textColor="#FFFFFF"
        android:id="@+id/shutterButton"
        android:paddingTop="32sp"
        android:drawablePadding="-22sp"
        android:text="SNAP"></Button>

输出

请把文字放在图片下面。非常感谢

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2016-04-13 08:44:51

android:drawableTop="@drawable/snap"代替android:background="@drawable/snap",摆脱android:paddingTop="32sp"android:drawablePadding="-22sp"

属性android:drawableTop负责绘制文本上方可绘制的图形。E.g

代码语言:javascript
运行
复制
<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:drawableTop="@drawable/snap"
    android:textColor="#FFFFFF"
    android:id="@+id/shutterButton" 
    android:text="SNAP" />
票数 3
EN

Stack Overflow用户

发布于 2016-04-13 08:46:17

代码语言:javascript
运行
复制
 <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:drawableTop="@drawable/snap"
        android:textColor="#FFFFFF"
        android:id="@+id/shutterButton"
        android:paddingTop="32sp"
        android:drawablePadding="-22sp"
        android:text="SNAP"></Button>
票数 1
EN

Stack Overflow用户

发布于 2016-04-13 08:47:40

这就是我用来完成这个任务的地方:请注意,我使用了PercentRelativeLayout。

代码语言:javascript
运行
复制
<Button
    android:text="@string/Tesksten" <-- and of course the text.
    android:id="@+id/btContent"
    android:drawableTop="@drawable/ic_menu" <-- display icon on top
    android:layout_width="0dp"
    android:layout_height="0dp"
    app:layout_heightPercent="16%"
    app:layout_widthPercent="100%"
    android:textColor="#000000"
    android:background="#f0f0f0"
    android:textStyle="bold"
    android:alpha="0.65"
    android:layout_marginBottom="10dp"/>

它看起来是什么样子:

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36593019

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档