How to use Nine-patch images correctly

爱⌒轻易说出口 提交于 2019-12-05 15:37:52

Are you using the draw9patch tool that comes with the sdk? it is quite handy.
Anyway:

  • It is vital that every pixel except the black ones are completely transparent.
  • The black pixels should be at the absolute top/bottom/left/right of the image.
  • The image should be named filename.9.png.

I have found the best and the simplest answer to make 9-patch image.

This is best link to create 9-patch image for all the resolutions - XHDPI, HDPI, MDPI, LDPI in just one click.

Let me know if you have any queries, and do upvote it, if it was helpful to you.

If you need an image which consists of a border with rounded corners, I don't have to create a 9-patch.

All you need is an XML like this stored in the res/drawable directory

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <corners android:radius="3.0dp" />

    <stroke
        android:width="2dp"
        android:color="@color/green" />

</shape>

Read more about drawable resources

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!