I have a fairly simple layout with an image, and some textviews wrapped in a vertical LinearLayout. Whenever I set the background of this layout to be a 9patch, the height of the layout seemingly gets set to the height of the 9patch (even though the 9patch seems to successfully stretch to be the height of the layout.)
If I use a solid background color, the height of the layout works as intended.
Here's a screenshot with the 9patch in place:
Here's a screenshot with a solid background instead of the 9patch (notice how the text is centered in the layout now):
And finally, here's the XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/show_gray"
android:gravity="center_vertical"
android:orientation="horizontal" android:weightSum="5">
<ImageView
android:id="@+id/imageView1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="4"
android:scaleType="centerCrop"
android:src="@drawable/temp_featured_banner" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#FF0000"
android:gravity="center"
android:orientation="vertical"
android:paddingLeft="30dp" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textColor="@color/white" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Small Text"
android:textColor="@color/white" />
</LinearLayout>
</LinearLayout>
... and just in case, here's a screenshot of draw9patch showing my 9patch drawable:
I suspected that the LinearLayout wasn't taller than the natural size of the 9patch (so there was nothing to stretch..), so I reduced the 9patch in height by 50%. The problem still existed.
Any ideas?
The top and left of the nine patch refer to the 'stretchable' area of the image. The right and bottom of the nine-patch define where the content should go - currently, you're just telling it to guess (and it guesses by putting all of the content in the line designated by the top left dot). from what I can tell from your image, you probably want a solid black line top to bottom (leaving out the corners, of course) on the right of the nine-patch, and a matching dot to your top-right black dot on the bottom. This tells the OS where to put the content in relation to the image so that it better knows how to stretch the image.
In the 9-patch program, draw lines on the bottom and right sides to choose areas that can be "collapsed". Might fix your issue.
http://developer.android.com/guide/developing/tools/draw9patch.html