gpt4 book ai didi

android - TextView 背景大小

转载 作者:行者123 更新时间:2023-11-30 02:41:29 25 4
gpt4 key购买 nike

我的布局中有 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/

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