【问题标题】:Textview background Size文本视图背景大小
【发布时间】:2014-09-05 14:36:21
【问题描述】:

我的布局中有 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 的背景大小适合动态填充它的文本?

【问题讨论】:

标签: android xml eclipse textview


【解决方案1】:

要动态获取背景大小,您可以使用:

tv = (TextView)...findViewById(...);
BitmapDrawable background = (BitmapDrawable)tv.getBackground();

然后得到高度和长度使用:

background.getTileModeX();
background.getTileModeY()

希望它能解决你的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-05-05
    • 2014-10-06
    • 2020-12-15
    • 2021-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-26
    相关资源
    最近更新 更多