0

let say I have Bitmap A with the dimensions 165x15.7 which is displayed correctly on 320x240 screen size with 0.75 density. if i want to show the bitmap images on different screen size like 480x320 with 1.0 density, how to set the bitmap width and height dynamically on different screen size? i want to do it programmatically,I don't want to use xml/ multiple layouts/ multiple dimensions. any help would be appreciated. thank you.

here is for the example

320x240 screen dimension

480x320 screen dimension

enter image description here

as you can see the screenshot above, the example logo look smaller on 480x320 screen dimension

Zoe
  • 27,060
  • 21
  • 118
  • 148
Willyanto Halim
  • 413
  • 1
  • 6
  • 19

1 Answers1

2

You can get the scale factor of device screen to scale the image size with this code :

getResources().getDisplayMetrics().density;

This will give you:

ldpi = 0.75

mdpi = 1.0

hdpi = 1.5

xhdpi = 2.0

xxhdpi = 3.0

xxxhdpi = 4.0

source : https://stackoverflow.com/a/10948031/6217595

zihadrizkyef
  • 1,849
  • 3
  • 23
  • 46