While developing an application this is what i did :
1.Kept 320*480 as my base resolution and 160dpi as my base density.
2.Kept all the images in drawable-mdpi folder
3.made use of dp while specifying the width and height of the images in xml layouts.
what i found was as its mentioned on the developer’s site if we use dp then it does scaling automatically scales up and scales down according to the screen.But i didn’t got the desired result and the images didnt scaled properly for the smaller device.
So what i did was
1.created the layouts in xml files
2. the set the width and height of the images at runtime in percent of the screen width and height
And by doing this i got the desired result.The images scaled properly on all the devices ranging for small 240*320 to tab 600*1024.
So my question is that as mentioned in the developer site should i use dp for specifying the width and height or should i do it programmatically.And if no what is the concept of dp and where can i use it ?
First thing, I think use of “dp” is good. There is no problem with that.
Secondly, to cope up with the problem you mentioned, the best way is to put the images of suitable sizes in ldpi, hdpi and xhdpi folders. Then you don’t have to adjust the layouts dynamically.
The ratio of image sizes in LDPI:MDPI:HDPI:XHDPI= 3:4:6:8
OR This is how you can predict the size of the device dynamically and then set the layout accordingly: