我的布局中有 textview,如下所示:
<TextView
android:id="@+id/actionbar_notifcation_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:padding="2dp"
android:background="@drawable/notif"
android:textColor="@color/wallet_bright_foreground_holo_dark"/>
有什么方法可以让 textview 的背景大小适合动态填充它的文本?
最佳答案
要动态获取背景大小,您可以使用:
tv = (TextView)...findViewById(...);
BitmapDrawable background = (BitmapDrawable)tv.getBackground();
然后获取高度和长度使用:
background.getTileModeX();
background.getTileModeY()
希望能解决您的问题。
关于android - TextView 背景大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25688345/