Android 文本视图背景大小

Android 文本视图背景大小,android,xml,eclipse,textview,Android,Xml,Eclipse,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:backgrou

我的布局中有如下文本视图:

<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"/>


是否有任何方法可以获取文本视图的背景大小,以适应动态填充的文本?

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

tv = (TextView)...findViewById(...);
BitmapDrawable background = (BitmapDrawable)tv.getBackground();
然后,要获得高度和长度,请使用:

background.getTileModeX();
background.getTileModeY()

希望它能解决您的问题。

看看这里,听起来您希望背景图像根据运行时设置的TextView文本的字符串长度动态增长/收缩?