我有一些像这样的透明背景文本
现在,当文本很小时,它看起来不错并且居中(我也有 android:minWidth="150dip"),但由于文本很大时它是 wrap_content
它像这样包裹。
有没有一种方法我可以在背景边缘和文本之间始终保持恒定的空间,并且使文本居中(一旦侧面固定,这将很明显)这是我的文本 xml
<TextView
android:id="@+id/title2"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:background="@drawable/tocheader"
android:gravity="center_vertical|center_horizontal"
android:minWidth="150dip"
android:text="example"
android:textColor="#ffffff"
android:textSize="18dp"
android:textStyle="bold" />
而且@drawable/tocheader
只是
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp"
android:shape="rectangle" >
<solid android:color="#88000000" />
</shape>