1

I am using image say 85x85 px (putting this image in drawable-mdpi)

and if i am displaying this image of 85x85 px on [320x480]mdpi screen size device it looks good, but while displaying this image on [480x800]mdpi device it looks very small.

I wants to know how can i resize this image of (85x85 px) so that it works fine for the device having screen width and height of 480x800, mdpi.

A.R.
  • 2,631
  • 1
  • 19
  • 22
  • If you use those images as drawable resources and you determine the view size of them by specifying a percentage of the width and height of the screen, you can just put this image in the `hdpi` folder and the Framework will automatically scale it down for you (this of course depends on the Android version you use and of the implementation you have chosen). – g00dy Aug 06 '13 at 14:40
  • Have a look here: http://developer.android.com/design/style/iconography.html – LuckyMe Aug 06 '13 at 15:00

4 Answers4

2

You have to set the image size in the xml in dp. This post is really helpful.

Community
  • 1
  • 1
Thomas Kaliakos
  • 3,274
  • 4
  • 25
  • 39
  • Actually i am using these images on canvas, so how can i set the image size in xml, because there is no use of xml file while using canvas. – A.R. Aug 06 '13 at 15:05
1

Consider MDPI image(let say 85x85) as baseline Create images as follow

FOLDER ImageSize Percentage

LDPI 64x64 75% of baseline

MDPI 85x85 100% BASELINE

HDPI 127x127 150% of baseline

XHDPI 170x170 200% of baseline

dinesh sharma
  • 3,312
  • 1
  • 22
  • 32
  • I am doing the same thing what you are saying, creating an image of 64x64 for LDPI,85x85 for MDPI, 127x127 for HDPI,actually i am using these images on canvas and all looks good, but while running my project on emulator using (5.1" WVGA, Screen 5.1", 480x800 large mdpi), the bubbles images looks very small comparing to size of device. – A.R. Aug 06 '13 at 15:20
0

Put the image in /drawable, and define the size of the image in your XML as 85dp, it will then be scaled for LDPI/HDPI/XHDPI/XXHDPI and god forbid XXXHDPI.

However, the better solution would to produce HDPI(128px)/XHDPI(170px)/XXHDPI(255px) version of the graphics and put them in /drawable-hdpi, /drawable-xhdpi, /drawable-xxhdpi respectively. This way you can provide the best experience for your users.


[Edit]

"dp" is Android's way of defining physical size of an UI objects, so a button of 48x48dp will have roughly the same physical dimension even when run on screen sizes between 240x320 to 1080x1920, for more information check Android developer site's Supporting Multiple Screens.

[Edit 2]

For images on canvas you can use this to calculate the scaled size of the image:

DisplayMetrics dm = new DisplayMetrics();
context.getWindowManager().getDefaultDisplay().getMetrics(dm);
int newSize = (int)(85 * (dm.densityDpi / 160f));
Kai
  • 15,284
  • 6
  • 51
  • 82
  • what does {85*dp*} means ? it makes no sence – dinesh sharma Aug 06 '13 at 14:36
  • @dineshsharma added reply to my answer – Kai Aug 06 '13 at 14:51
  • my concern was with * in 85*dp* it was misleading thing that's it I know what is DP and SP. Now you have made it 85dp problem solved :) – dinesh sharma Aug 06 '13 at 14:55
  • Yeah I was using the **bold** mark but for some reason it showed up the way it was, so I removed the mark altogether, sorry about the confusion :-/ – Kai Aug 06 '13 at 15:05
  • Actually I am using images on canvas, and there is no xml file in my project where i can define the size of my images in dp or sp. – A.R. Aug 06 '13 at 15:30
  • @A.R. Edited my answer. And you should really include the fact that you are using a Canvas in your question, it's very pertinent to the question. – Kai Aug 06 '13 at 15:59
  • @KAI, Hey I am sorry about that, I really forgot to mention that i am using my images on canvas. – A.R. Aug 07 '13 at 08:07
0

The better solution for this is to produce LDPI,MDPI,HDPI,XHDPI,XXHDPI sized images and place it inside the corresponding folders.

Hybrid Developer
  • 2,320
  • 1
  • 34
  • 55
  • I am doing the same thing what you are saying, creating an image of 64x64 for LDPI,85x85 for MDPI, 127x127 for HDPI,actually i am using these images on canvas and all looks good, but while running my project on emulator using (5.1" WVGA, Screen 5.1", 480x800 large mdpi), the bubbles images looks very small comparing to size of device. – A.R. Aug 06 '13 at 15:19
  • re-size the image try it up to the limit – Hybrid Developer Aug 06 '13 at 15:24