1

What I have In my project is a drawable folder in which I've placed all the drawables I need to resize some of them to do that I placed values folder:

values-normal-xhdpi values-normal-mdpi ...

all the values that are in the xhdpi must be divided by 80/60=1.333 so that I get the same display for both devices...

why is it like that? when I divide it by 2 I get small buttons on the mdpi device;

and when I keep the dimensions the same I get very big buttons on the mdpi device;

Example: in the values-normal-mdpi:

<!-- In the about the progragm activity the buttons -->
    <dimen name="aboutproductimgwidth">73.5dp</dimen>
    <dimen name="aboutproductimgheight">73.5dp</dimen>

    <!-- the logo in the animation activity -->
     <dimen name="logoimgwidth">162dp</dimen>
     <dimen name="logoimgheight">162dp</dimen>

in the values-normal-xhdpi:

<!-- In the about the progragm activity the buttons -->
    <dimen name="aboutproductimgwidth">98dp</dimen>
    <dimen name="aboutproductimgheight">98dp</dimen>

    <!-- the logo in the animation activity -->
     <dimen name="logoimgwidth">216dp</dimen>
     <dimen name="logoimgheight">216dp</dimen>

when I placed these values I've got the exact same display on both devices.. and that's what I need.

EDIT1 Even when I did it in another way, and that's by placing an image of 160px in the drawable-normal-xhdpi folder and another one with 80px in the drawable-normal-mdpi folder I've got different display on both devices; on the mdpi device I've got really large buttons and on the xhdpi device I've got a nice display why?!! although I did what they said I divided the image of xhdpi on 2;

EDIT2 sorry I placed some photos but can't keep them online for too much time.. but what I have in my display: ONE DEVICE HAS A TEXT UNDER THE BUTTONS AND A TEXT ABOVE THE BUTTONS BECAUSE THE BUTTONS ARE TOO LARGE AND IN THE OTHER DEVICE I AM GETTING THE TWO TEXTS ABOVE THE BUTTONS BECAUSE THE BUTTONS ARE JUST AS BIG AS I NEED THEM TO BE.. ALTHOUGH I USED IN THE FIRST DEVICE BUTTONS 80PX BECAUSE IT'S A MDPI DEVICE AND IN THE SECOND ONE 160 PX BECAUSE IT'S XHDPI

Learning Android
  • 273
  • 4
  • 17
  • Do not use decimal values. Replace 73.5dp with 73dp. There is really no such thing as half a pixel. If you really want to play it safe, make all your dimensions divisible by 2, or may be even 4. That's what I do, although I know it's not required. – Stephan Branczyk Jan 18 '14 at 19:51
  • ok thanks will do that :) – Learning Android Jan 18 '14 at 19:52
  • Also, I'm not even sure why you're using the values folders. The resizing should be happening in the drawable folder. Is this some new Android best practice that I don't know about yet? – Stephan Branczyk Jan 18 '14 at 19:55
  • no, It's just my own solution so that I don't place too many drawable folders.. – Learning Android Jan 18 '14 at 19:58
  • Why? What have you been putting in them? How much memory do they take? You should try using the drawable folders. Or if you really don't like having more than one, then you should just let Android handle the auto-scaling for you. – Stephan Branczyk Jan 18 '14 at 22:39
  • because I don't want to put lots of images this will take too much memory.. I add the image in the drawable folder and I add the dimention of this image for each device in the values folder and I tell the image to take this demension from the values folder layout-width:"@dimen/imgwidth" it's working just fine not taking too much memory not taking too much time.. besides that's my first app so if i find any cons I will change it.. – Learning Android Jan 19 '14 at 03:54
  • Check out this http://stackoverflow.com/questions/16706076/font-size-and-images-for-different-devices – Bhavesh Jethani Jul 24 '14 at 09:31

3 Answers3

1

If you did it properly, then the image in your drawables-mdpi should be 1/2 the size of the image in xhdpi.

What you're seeing on the screen is that a typical mdpi device is 320 px while a typical xhdpi is 720 px. So if you made two buttons, each 1/2 the screen size, then the xhdpi buttons should be 360px. Following "procedure" means half sized 180px buttons in mdpi. But on the mdpi screen 2 buttons would be 360px, and not fit. To get them to fit you would need to reduce them 30 px, or about 13.33%

Sounds like the screens you are looking at may not be typical screens, but the root of the problem is that you are adjusting the image size in both the drawables and in the values folders. You need to redesign your approach to handling different screen densities - pick one or the other, but probably not use both unless you have a very unusual use case.

Jim
  • 10,172
  • 1
  • 27
  • 36
  • no I am not adjusting their size in the values folder and the drawables folder at the same time; first I tried the first one when it didn't work I tried the other.. Yes that's what is happening on the mdpi the buttons don't fit properly and I am just wondering why but when I placed a 160px in the hdpi and 60 px in the mdpi I got the needed result so my I need so my scale number is 80/60 which is 80dp=160px(xhdpi screen) and 60dp=60px(mdpi screen) so is that normal? – Learning Android Jan 18 '14 at 21:22
  • Did you place a 160px image in the xhdpi folder? And then 60px image in the mdpi folder? As in your comment? You are using values with dp's - dimen adjusts 160 to 160px for mdpi screens and a value of 160 to 320px on xhdpi screens. Typically, dimen's are used for non-drawables (like text) or stock widgets (like "Button"). So what you're doing is adjusting the image size in the drawables, then using dimens with dp to do another adjustment. Place one image in a folder named "drawables" and then use dimens, or create two images and stop using dimens. – Jim Jan 18 '14 at 21:44
  • yes that's what I did I placed images in a folder called drawables and I called dimens without creating drawable-normal.. folders; but the size of the buttons where 160px for xhdpi and 60px for mdpi so that they fit as I want them to be.. – Learning Android Jan 18 '14 at 21:46
  • then yes, your statement is correct - 80dp = 160px on xhdpi and 80dp = 80px (or 60dp = 60 px) on a mdpi screen. Does this answer your question(s)? – Jim Jan 18 '14 at 21:52
  • yes but I am trying to find out how the scaling work... I mean I should take it 80/60 on this device and how to detect it on the other devices.. that's what I am trying to do.. – Learning Android Jan 19 '14 at 03:51
  • So what I have is 1280x480 screen device and 720x320 screen device so 1280/480=160/60 that's why the 160px on the xhdpi screen is 60 px on the mdpi screen now I found it but what I want to know is will I be able to use this proportion for all the devices.. – Learning Android Jan 19 '14 at 04:10
  • what you mentioned in the begining is what I needed to know thanks. – Learning Android Jan 19 '14 at 09:44
  • 1
    you may not be able to use it for all devices. If the image size is critical to your app, then use displayMetrics to detect screensize and adjust accordingly. You should be able to find a lot of references here on SO – Jim Jan 19 '14 at 17:00
0

You are having problems in setting the correct dpi of image for different drawable folders. If you want to automatically generate a image for all required sizes the please use http://android-ui-utils.googlecode.com/hg/asset-studio/dist/index.html.

Here you can upload your image or use text/clip art and it will provide you with a zip containing images of all dpi.

Rohan Kandwal
  • 9,112
  • 8
  • 74
  • 107
  • thanks tried that out but same problem.. could it be that this device is a mdpi but it takes it's sizes from hdpi or something or what could be the problem because I am having different display between my device which is normal-xhdpi and the emulator which is normal-mdpi – Learning Android Jan 18 '14 at 19:52
  • Actually I am confused as to what you want to say. You are putting 160px image in xhdpi and 80px image in mdpi device. And you are not getting correct ratios of the image? – Rohan Kandwal Jan 18 '14 at 19:55
  • what you really want ? equal size image on both devices? why don't you make a 320px image that you can keep in xhdpi and keep 160px in mdpi? – Rohan Kandwal Jan 18 '14 at 20:02
  • that will help a lot. – Rohan Kandwal Jan 18 '14 at 20:05
0

You need to add settings for different device sizes in your AndroidManifest.xml. You can see that settings here.

Roman Black
  • 3,501
  • 1
  • 22
  • 31