views:

49

answers:

2

Say I add a linear layout with top padding of 20. Does it mean that the layout is rendered with 20 pixels of padding in all phones? Or does it scale according to the height/width/density of the phone?

Thanks Chris

A: 

It depends how extactly you have defined the padding. If in your layout file you wrote for example

android:paddingTop="20px"

Then yes it is 20 pixel on every device.

Roflcoptr
I am doing this in code, so I am setting layout.setPadding(0, 20, 0, 0);
Chris
Ah ok. Sorry didn't get that. I assume that this are pixels on every devices, but I'll would wait for other answers ;)
Roflcoptr
+1  A: 

In Java code is going to be pixels on all devices. If you want to make it density respected (like using 20dp or 20dip) then you can use:

float density = context.getResources().getDisplayMetrics().density;
setPadding(20 * density, blah, blah, blah);

That density var will be 1.0 on the medium phones, or more or less depending on the density of the screen.

Moncader