Laying in different phones

Say I'm adding a linear layout with top padding 20. Does it matter that the layout is displayed with 20 fill pixels on all phones? Or does it scale according to the height / width / density of the phone?

+3
source share
2 answers

Java code will have pixels on all devices. If you want to make its density respected (e.g. using 20dp or 20dip), you can use:

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

This var density will be 1.0 on average phones or more or less depending on the screen density.

+3
source

, . , ,

android:paddingTop="20px"

, 20 .

0

Source: https://habr.com/ru/post/1756264/


All Articles