Android | How do I define the height and width of a 9-Patch PNG so it won't get pixelized
I have discovered the main idea of how to deal with regular PNG for Android. Let's say I have created in my computer an icon the size of 60*120px. I know that for hdpi (800*480px) I need to divide it by 1.5 in order to get the right dp - so i开发者_开发知识库t will be 40*80dp.
so far so good - but - what happens when I need to define a 9-Patch so it won't get "pixelized". the problem is that all 9-patch files in my android looks all pixelized - I am sure it is because there is no definition in the file to "squeeze it" by 1.5 in order for it to display the 9.PNG well.
What am I missing? What do I need to do to achieve the right dp for a file that basically has a fluid height and width?
well you need to have 2 seperate icons for hdpi and mdpi for example. i usually have them laid out in a hdpi photoshop file and extract them from there (one png as hdpi and one as mdpi by scaling the hdpi one -preferably scale a vector graphic rather than a regular image by 1/3 from the hdpi graphic.) and also this way i almost never have to input my width and height restrictions to the image inside a layout because it looks exactly like in photoshop's layout. i just set it to wrap content. as far as making .9's you just need to do the same process as a regular png but define via the draw9patch tool an area that will be scaled in case the .9 needs to be rescaled.
just see how the button for example is made. You have a 9 that has the normal height of the button but just defined an area which can be scaled(the middle of the button) in case the button is stretched by height or width which means the middle will get scaled but since its a color not an image it doesn't destort the look, however the edges of the button always stay the same and never get stretched no matter how big the button gets.
精彩评论