android - TextView 文本及其可绘制到 textview 中心
问题描述
我有一个带有drawableleft的textview。由于 textview 覆盖了屏幕的整个宽度,所以我想要 textview 文本及其可绘制的左侧到 textview 的中心。目前只有文本与它的中心对齐,drawable 总是在它的最左边。所以请给我一些建议。
<TextView
android:layout_marginLeft="@dimen/_10sdp"
android:layout_width="0dp"
android:layout_height="@dimen/_40sdp"
android:layout_weight="5"
android:gravity="center"
android:drawableLeft="@drawable/ic_cloud"
android:paddingLeft="@dimen/_10sdp"
android:text="@string/up"
/>
解决方案
您无法使用drawableleft
. 与和分开Layout
使用ImageView
,TextView
如下所示:
<RelativeLayout
//add necessary attributes
android:gravity="center_horizontal">
<ImageView
//Add your image here
/>
<TextView
android:layout_marginLeft="@dimen/_10sdp"
android:layout_width="0dp"
android:layout_height="@dimen/_40sdp"
android:layout_weight="5"
android:paddingLeft="@dimen/_10sdp"
android:text="@string/up" />
</RelativeLayout/>
希望这可以帮助
推荐阅读
- azure - 哪些 Azure 产品可供公共用户上传他们的私人数据?
- python - Chrome Webdriver 不加载默认配置文件
- javascript - three.js — 如何在加载器之外选择网格?
- r - 如何按组根据列值创建“块”?
- javafx - JavaFX 12 中的 WebConsoleListener IllegalAccessError
- python - 是什么阻止我的异步代码运行异步?
- icalendar - 无法通过 MailKit 发送带有图像附件的 iCal.net
- sql-server - 使用 SELECT 结果作为列名
- authentication - 如何在 ajax 中设置 document.cookie?
- python - 查找 docker 镜像的依赖项