Android: different image based on screen size

Is there a way for Android to choose a different image based on screen size? According to the docs and my testing, images should be placed in folders like drawable, drawable-mdpi, drawable-hdpi, etc.

These folders, however, are screen type, not screen size. Layout folders are used to handle different screen sizes, but they do not allow you to store images in them. Xml files only.

Therefore, if I run my application on two devices with the same teps, but with different screen sizes, the same image is selected from the same accessible folder. I really want the larger image to be selected for the larger screen and the smaller image for the smaller screen.

Thank you for your help.

+3
source share
2 answers

You can use 9 patch images. Image with 9 patches can be stretched without loss of quality. You can refer to the following link for more information http://developer.android.com/guide/developing/tools/draw9patch.html

+1
source

Yes, you are right, this is how Android works, saving different images in specific folders (l, m, h and xh-dpi).

Where is your problem?

Do you want to save images for all screen resolutions? Too many of them. Can you write more specific information about what you want to achieve?

If you have a problem with layouts.xml just check:

android:scaleType="..."
+2
source

All Articles