I have a 9 patch png in a RelativeLayout and everything looks great! However, when i create a textView in the RL, the textView is not at the top of the parent… I also tested this on the phone, same result… why does it do this?
Thanks for your assistance!
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/testLL"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/backrepeat"
>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="15dp"
android:layout_gravity="center_vertical|center_horizontal"
android:background="@drawable/contentbox">
<TextView
android:text="Test"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"/>
</RelativeLayout>
</LinearLayout>


In looking up how 9patches are rendered, it basically turns the non-stretchable areas into default layout padding. This is to facilitate easy entry of stuff into the target (stretchable) area, without having to go in and define paddings manually. By assigning a 9patch, you are using it’s padding. It assigns paddings to top left right and bottom based on how many px the 9patch has until it reaches the stretchable center.
You may try doing something like android:paddingTop=”-50px” in your textView and see what happens. I haven’t tested this, so I’d be interested to see how it turns out.
Edit to your comment with pic: Since your 9patch’s top stretchy region doesnt start for about 90 px, its automatically going to pad the first element 90 px down, to place it within the “stretchy target” region. Try my above suggestion to see how it works, I’m pretty interested to see how it turns out. I don’t have my IDE accessible from my Mobile, otherwise I’d test it for you 😉
Edit: I apologize, I’ve been saying “padding” instead of margin. But the theory is the same. Not modifying the above for permanent documentation of my idiocy.