Tutorial :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?


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.


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


Then yes it is 20 pixel on every device.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »