Different 9-patch images for different densities?

安稳与你 提交于 2019-12-12 08:17:33

问题


I have the same 9-patch images in MDPI / HDPI / xhdpi. Is there a particular reason why it will not be saved for the smallest size? The stretchable areas scale automatically when the content is greater, for example a background as a 9-patch.

Example background:

mdpi:

hdpi:

xhdpi:


回答1:


Many nine patches are so small that they normally don't need to be recreated for different screen sizes.

In your example the corners of the background are not scaled. If you just use the same corners on all resolution they would have a different size on different resolutions. On smaller phones the corners would appear bigger on bigger phones the corners would appear smaller.

Another example would be a line. If you have a line that is has a special effect and you create it as a nine patch for mdpi screens and the line is two pixel high. Just reusing this drawable without scaling on a xhdpi screen would make your line two pixel high on this screen. But because the screen has smaller pixels (higher resolution, same display size) the line would appear thiner.

Therefore you always need to create a 9-Patch for every resolution, or as @Shubhayu said only produce high resolution nine patches and accept that they get blurry if the system scales them down for other resolutions.




回答2:


You don't need to put different sized 9-patch images in all the 3 folders. Just put the one with the highest resolution in your drawable folder. Android will pick it up for all your different densities.

Also the crispness of your image depends upon the resolution of the image. You'll see blurry stretching occur for high density devices if you save the smallest size (ie with the least resolution) This will not be evident if the background image is plain colored. You'll notice the difference when the background has some designs/repeatable of gradients.

Edit: Ever since writing this post, I have discovered a lot more stuff about the 9-patch. 9-patch images do not scale down. Best would be to put the smallest size image. And based upon how it looks for other densities, you should make 9-patch images for the affected densities. Here are more details on it,

http://www.shubhayu.com/android/9-patch-image-designers-vs-developers



来源:https://stackoverflow.com/questions/9941471/different-9-patch-images-for-different-densities

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