Search code examples
androidnine-patch

9 path not stretch correctly


I know there is a lots of other questions about this but I try all of them and nothing works for me. I want to create a button with 9 patch background. This is my 9 patch image :

enter image description here

I create this with draw9patch.bat in android sdk :

enter image description here

And I use this xml to create my button :

<Button
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:text="New Button"
  android:id="@+id/btnTest"
  android:background="@drawable/ic_btn2" />

But the result is weird :

enter image description here

For test purpose I download some 9 patches and replace them with my image but those images have this problem too. I use android studio 2. what cause this problem?


Solution

  • Make sure the file's name ends with .9.png.