我使用9补丁图像作为按钮背景,如下所示

之所以是这样,是因为我不希望它被拉伸,我只使用这种技术正确地显示文本如下:

问题是,当使用Eclipse布局编辑器时,一切似乎都正常,但当我在手机上启动应用程序时,背景显示为9补丁图像。拉伸线是强制性的吗?
注:我不想把这张照片拉长
发布于 2014-05-07 16:40:10
我个人就是这样做的:

文本区域将垂直地和水平地伸展,不包括图像,但只拉伸两侧。
通过使用此测试布局:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black"
>
<TextView
android:id="@+id/txtTop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:gravity="center_horizontal"
android:background="@drawable/orange_contact"
android:text="My very very very long text"
android:textColor="@android:color/black"
android:textSize="20sp"
android:textStyle="bold"
/>
<TextView
android:id="@+id/txtLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/txtTop"
android:layout_alignParentLeft="true"
android:gravity="center_horizontal"
android:background="@drawable/orange_contact"
android:text="M\ny\n\nt\na\nl\nl\n\nt\ne\nx\nt"
android:textColor="@android:color/black"
android:textSize="20sp"
android:textStyle="bold"
/>
<TextView
android:id="@+id/txtUnder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/txtTop"
android:layout_toRightOf="@id/txtLeft"
android:background="@drawable/orange_contact"
android:text="My multiline text\nMy multiline text\nMy multiline text"
android:textColor="@android:color/black"
android:textSize="20sp"
android:textStyle="bold"
/>
</RelativeLayout>我得到了这个结果:

发布于 2014-05-07 16:35:00
使用图像的精确宽度和高度作为Button的尺寸(在dp中)。请注意,Button (或TextView)不会根据其背景调整自己的维度。
或:
您可以使它在person图标的任何一侧水平拉伸,并在文本区域内垂直拉伸。
https://stackoverflow.com/questions/23523087
复制相似问题