My Android app looks great at 480x800 pixels resolution but it breaks at LDPI screen with 240x400 pixels. I know I can get scaling factor of screen in activity using getResources().getDisplayMetrics().density
which would give the exact float
value depending upon screen resolution.
In my app, I have used RelativeLayout
and ImageView
s within it, and set the margins of images using setMargins()
, as this method uses pixels in int
for its top, left, bottom and right values, how can I set these values using DPI factor I got? (which is a float). We have Math.floor()
but I'm positioning images at very particular locations using pixels, and DPI factor returned by method has very specific value at decimal places which can't be ignored, so casting to int
doesn't work for me.
Update
Also, I use lp.setMargins(100,200,0,0);
to set the margins, what modification I'll be making in it to use DPI factor I recieved from device?
P.S. I know its more a mathematical issue rather than programming, but I'm poor with math, sorry.