How to use Nine-patch images correctly

感情迁移 提交于 2020-01-02 06:24:06

问题


I want to create some kind of row image that looks like that

but I want it to scale with the screen size and density. So reading this http://developer.android.com/guide/developing/tools/draw9patch.html and this http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch I startet creating a Nine-patch image.

But when I import it and use it in my android project it looks like that

As you can see the little black line that was drawn with the draw 9 patch tool is still visible. Why?

Here is the 9.png image


回答1:


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.



回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/8563435/how-to-use-nine-patch-images-correctly

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