简体   繁体   中英

Android 9 Patch Strange Behaviour

I am a designer and am currently working with my developer on an Android app which basically loads an ImageView which we would like to apply a 1px grey border around it with a 2px drop shadow on the bottom.

I have created a 9 patch file which the developer has applied to the ImageView, however I notice that Android seems to be doubling up the borders.

Here is the 9 patch image: http://imgur.com/l1yXTyr

This means that now its no longer a 1px border on the top, left and right. Its setting it as 2px on left and 3px on the right!

So, I ask you superbly clever individuals:-

  1. Is this an issue that lies with the 9 patch creation?
  2. Could you point me in the right direction if this could be done via code?

A big thank you to everyone who responds with pointers and suggestions. It is very much appreciated.

I guess you put the 9-patch drawable in res/drawable-mdpi and you run the app on hdpi device. Android upscales the drawable, which almost always is not what you want.

There are two solutions, depending on how your 9-patch looks like:

  1. If the 9-patch is only 1px frame and 2px shadow and there are no areas that should be scaled (for example padding), you can just put the 9-patch in drawable-nodpi folder.
  2. If there is some area that should be scaled and you want to have exactly 1px frame on every device, you have to prepare 9-patches for every pixel density with properly resized scalable areas and 1px frame.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM