How are PNG files defined as drawable objects resized based on the resolution of the Android phone?

StackOverflow https://stackoverflow.com/questions/3890018

문제

I have a PNG file that is 32x32 pixels. I use 8 of these as drawables in a row for my app. These drawables are not in the hdpi, mdpi, or ldpi folders. I’ve found that when starting any of the 3 standard size emulators, the screen view with all 8 drawables looks pretty much the same.

I note that the ldpi emulator I’m using (QVGA) has a resolution of 240x320. 8 x 32 = 256, so since I can see all my drawables (and space in-between) I’m betting something is changing their size.

I’ve read the Supporting Multiple Screens document at the Android developers page, but I still don’t understand what is actually happening. Could you put your own words to explain what is happening to the size of my drawables and how the SDK knows to automatically modify them?

도움이 되었습니까?

해결책

Of course - the system automatically resizes your images from the drawable directory to correspond to the DPI of the device if you don't define your own. So in fact the 'drawable' directory is pretty much the same as the 'drawable-mdpi' directory, and because you don't have the ldpi and hdpi versions defined the system automatically builds them out of your mdpi resources. See (1.) here: http://developer.android.com/guide/practices/screens_support.html#support - "Pre-scaling of resources (such as image assets)"

Of course your icons will look somehow ok on ldpi devices but ugly on hdpi devices. That's because the mdpi icons are scaled to match higher dimensions, effectively resulting in less information per pixel.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top