android - TextView 背景大小

标签 android xml eclipse textview

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

相关文章:

android - 如何启用 NFC 设置

xml - 使用 XML::Twig 对 XML 字符串进行基本解析

javascript - 用 jquery 读取这个 xml

xml - 使用 XSLT/XPath,如何匹配 null namespace 中的任何元素?

java - 如何计算自记录输入以来的天数?安卓、SQLite、Java

Android 菜单项在 'swiping' 之后不可点击

php - 是否可以配置 Eclipse 以防止某些警告出现在“问题” View Pane 中?

eclipse - 使用 Connector Discovery 升级 Eclipse 中的 Subversive 连接器

java - 如何让我的 JButton 与我的 JFrame 连接?

java - 如何解决 "The specified Gradle distribution ' https ://services. gradle.org/distributions/gradle-4.10.1-all.zip'不存在。”