9-patch in the selector shows black dots

I want to change the background of the layout when I click it. The layout does not always have the same shape, so I created an image with 9 patches that will support centering the image. My image looks like this:

enter image description here

Then my xml selector looks like this:

<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android" > <item android:state_pressed="true" android:drawable="@drawable/my_selector" /> <item> <shape android:shape="rectangle"> <solid android:color="#00ffffff" /> </shape> </item> </selector> 

When I had this code and my image was not a 9 patch, it was stretched to fill. Despite the fact that I changed the image to 9-patch, it still treats the image as a regular .png file. There are even black dots in the corner and all that.

enter image description here

I am wondering why the 9-patch image of the image is not respected and is simply treated like a regular .png file.

+4
source share
1 answer

I believe the problem is that you are using two dots in the lower and right parts of the image. I'm not sure that they know how to handle disjoint areas in these two dimensions. You essentially say that part of the content of this image consists of four areas with one pixel, which is the intersection of four points in the right and lower borders.

If you choose this, I think it should stretch a lot more predictably for you.

+4
source

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


All Articles