For example,we have pixels. However, pixels are not constant. I would imagine that high resolution android screens will have more pixels.
Then we have density, which doesn’t seem to help a lot. It’s not as precise as pixels and still not constant. A high resolution will have high numbers of “densities”
Do we have something like 10% of screen size. Is it common among programmers to do so?
Never (or almost never) work with absolute pixels.
If you want to work with percentages of a screen’s layout then use
layout_weight.The following condensed XML layout file shows a vertical
LinearLayoutwith twoTextViewwidgets each within their ownLinearLayouts. The innerLinearLayoutshave their height set to0dpbut the ‘sum’ of the ‘weights’ (0.9 + 0.1) equals 1 therefore the first innerLinearLayoutgets automatically expanded to 90% of the height of the screen whilst the second gets 10%.The numbers you use don’t matter…they could be 9 & 1 or 90 & 10 or 900 & 100…it comes down to the total sum and what each represents as a percentage. The layout inflation process will do the rest without you needing to know about absolute pixels.