【发布时间】:2022-04-07 10:27:06
【问题描述】:
我为 textview 使用椭圆形背景,但问题是,我必须在 xml 中手动设置 textview 的高度和宽度,然后它才会看起来像一个圆圈,有没有办法让圆形背景重新调整大小自己根据文本长度动态吗?
circle.xml
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid
android:color="@color/Color_500"/>
</shape>
layout.xml
<TextView
android:layout_width="56dp" //is it possible to make it dynamic according to the text length?
android:layout_height="56dp"
android:background="@drawable/circle"
android:text="@string/longtext"/>
【问题讨论】:
-
当然:创建您的自定义
android.graphics.drawable.Drawable类并使用您喜欢的任何内容覆盖其draw方法 -
嗨赛,你有解决这个问题的办法吗?任何帮助将不胜感激。