Chris
Chris

Reputation: 361

Padding in different phones

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?

Upvotes: 3

Views: 1728

Answers (2)

Moncader
Moncader

Reputation: 3388

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.

Upvotes: 4

anon
anon

Reputation:

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.

Upvotes: 0

Related Questions