开发者

Padding in different phones

开发者 https://www.devze.com 2023-01-08 10:03 出处:网络
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开发者_高级

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

android:paddingTop="20px"

Then yes it is 20 pixel on every device.

0

精彩评论

暂无评论...
验证码 换一张
取 消