gpt4 book ai didi

android - 使用 drawableBottom 时居中文本

转载 作者:行者123 更新时间:2023-11-30 01:46:27 28 4
gpt4 key购买 nike

我正在使用下面的方法

我拥有的 TextView 中的 setCompoundDrawablesWithIntrinsicBounds(null,null,null,drawable)。可绘制对象位于文本下方,但问题是它从文本开始的地方开始。有什么方法可以设置它,使图像上方的文本水平居中?

例如,代替

Sample Text
----------------
| |
| |
----------------

让它看起来像那样

  Sample Text
----------------
| |
| |
----------------

PS:我知道我可以将 Layout 与 TextView 和 ImageView 一起使用并对齐它们,但我试图只使用 TextView 但它本身来显示文本和图像

谢谢

最佳答案

试试这个,

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableBottom="@drawable/ic_launcher"
android:gravity="center_horizontal"
android:text="Hello Android" />

</LinearLayout>

输出看起来像这样,

enter image description here

关于android - 使用 drawableBottom 时居中文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33646158/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com