开发者

Android - Cascading drawable folders and default drawables

I have the following drawable folders

/drawable/
/drawable-hdpi/
/drawable-ldpi/
/drawable-mdpi/
/drawable-xhdpi/

If I have an image resource, do I need to create 5 (or 4?) different resolution versions of the file? Let's say I make just two versions and put them in their respective folders:

/drawable/
/drawable-hdpi/image.png
/drawable-ldpi/
/drawable-mdpi/image.png
/drawable-xhdpi/

What happens when someone on a LDPI or XHDPI device visits an Activity that needs to display image.png? Does it just not show it? Does the app crash? Or does Android follow a resource cascading system, show the version that is nearest to the current screen density?

Also, in this case I don't have an image.png in the /drawable/ folder. Is this bad? Should every single resource have (at minimum) a version in the /drawable/ folder?

Also, if you have specified all 4 screen density drawable folders (xhdpi, hdpi, mdpi, ldpi), then what is the point of the normal 开发者_JS百科/drawable/ folder? When will it ever get used?


If I have an image resource, do I need to create 5 (or 4?) different resolution versions of the file?

No, you don't have to

What happens when someone on a LDPI or XHDPI device visits an Activity that needs to display image.png? Does it just not show it? Does the app crash? Or does Android follow a resource cascading system, show the version that is nearest to the current screen density?

Android uses a nice cascading system for its resources. This page explains it a bit. Afaik LDPI devices use the MDPI resource if a LDPI resource isn't available, XHDPI uses HDPI resources. (I could be a bit off, I can't recall the exact rules) Your app doesn't crash. Your app crashes if you only have higher resolution resources than the screen can take.

Also, in this case I don't have an image.png in the /drawable/ folder. Is this bad? Should every single resource have (at minimum) a version in the /drawable/ folder?

No, not necessary.

Also, if you have specified all 4 screen density drawable folders (xhdpi, hdpi, mdpi, ldpi), then what is the point of the normal /drawable/ folder? When will it ever get used?

The drawable folder is for images that don't need scaling, and things like shape drawable resource XML files etc.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜