How to use images with nine patches

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

enter image description here

but I want it to scale with the size and density of the screen. Therefore, by 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'm starting to create a Nine-patch image.

But when I import it and use it in my Android project, it looks like

enter image description here

As you can see, the little black line drawn with patch tool 9 is still visible. What for?

Here is the 9.png image

enter image description here

+4
source share
3 answers

Do you use the draw9patch tool that comes with sdk? it is very comfortable.
Anyway:

  • It is very important that every pixel except black is completely transparent.
  • Black pixels should be in the absolute upper / lower / left / right value of the image.
  • The image should be named filename.9.png.
+7
source

I found the best and easiest answer to make a 9-patch image .

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

Let me know if you have any questions, and do it if it was useful to you.

enter image description here

+4
source

If you need an image consisting of a rounded border, I don't need to create a 9 patch.

All you need is the XML stored in the res/drawable

 <?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> 

Learn more about available resources.

+1
source

Source: https://habr.com/ru/post/1387052/


All Articles