Search code examples
androidnine-patch

Nine-patch image to draw 1 pixel border around TextView


enter image description here <-- This is a 3x3 image. Sorry.

I use the following 3x3 images.

So, when I open with draw9patch.bat, and added 2 pixels on top and left respectively, I get the following images.

enter image description here

I expect if I apply this image to TextView, my entire TextView will have 1 pixel width border around itself.

However, I am only manage to get "half border". The borders at right and bottom are missing.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_horizontal|center_vertical"
    android:orientation="vertical"
    android:background="#ffffff" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView"
        android:background="@drawable/border" />

</LinearLayout>

enter image description here

Is there anything wrong with my 9 patch image?

enter image description here <-- 9 patch image for your testing purpose.


Solution

  • Try adding 1px empty space around it. See attached image.

    padded bg