3

Is there a way to have Android select a different image based upon the screen size? According to the docs and my testing, images must be placed in folders like drawable, drawable-mdpi, drawable-hdpi, etc.

These folders however relate to the screen dpi and not the screen size. The layout folders are used to handle different screen sizes but they don't allow you to store images in them. Only xml files.

So if I run my app on two devices with the same dpi but with different screen sizes, the same image gets selected from the same drawable folder. What I really want is for a larger image to be selected for the larger screen and a smaller image for a smaller screen.

Thanks for your help.

Johann
  • 27,536
  • 39
  • 165
  • 279
  • you can find some help from here http://stackoverflow.com/questions/16706076/font-size-and-images-for-different-devices/16910589#16910589 – Bhavesh Jethani Jul 16 '14 at 06:53

2 Answers2

2

Yea, you are right, this is how works Android, by saving different pictures in particular folders (l,m,h and xh -dpi).

Where is your problem?

You want to keep images for all screen resolutions? Its too many of them. Can you write more specific what you want achieve?

If you have a problem in layouts.xml, just check:

android:scaleType="..."
goodm
  • 7,275
  • 6
  • 31
  • 55
  • I have logo image. On a large screen I want the larger image selected and on the smaller screen a smaller image. I suppose I could just use a larger image and somehow have Android scale it down for the smaller screen but I'm not sure how to do that. – Johann May 08 '12 at 08:33
  • Like goodm said, put the different images in the different image folders. Android will automatically select the image corresponding with the current screen size. – Wottah May 08 '12 at 08:48
  • to scale image you can use just scaleType in your xml file. To scale it more precisely use 9-path (android -> tools -> draw9patch). – goodm May 08 '12 at 09:08
1

You can use 9-patch images. A 9-patch image can be stretched without loosing quality. You may refer to the following link for more information http://developer.android.com/guide/developing/tools/draw9patch.html