Reputation: 10646
I'm using a 9 patch image for a button background, like so
The reason why it is like this is that I don't want it to be stretched, I'm only using this technique for displaying the text properly like this :
The problem is that, when using Eclipse layout editor everything seems to work just fine, but when I launch the app on the phone the background displays as 9-patch image. Are the stretching lines mandatory ?
N.B : I don't want to stretch the image
Upvotes: 0
Views: 159
Reputation: 38098
This is how I, personally, would make it:
The text area will stretch vertically and also horizontally, non including the image, but stretching the two sides only
By using this test layout:
<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>
I got this result:
Upvotes: 3
Reputation: 5151
Use the exact width and height of the image as the dimensions of the Button
(in dp). Note that a Button
(or TextView
) will not adjust its own dimensions according to its background.
OR:
You can make it stretch horizontally on either side of the person icon and stretch vertically within the text area.
Upvotes: 1