Learn about three property values before learning the Android layout:
1, Fill_parent:
Setting the layout of a component to fill_parent will force the component to expand to fill as much space as possible within the layout unit
2, Match_parent:
Android2.2 in Match_parent and fill_parent is a meaning. Two parameters meaning, match_parent more appropriate,
So from 2.2 onwards two words can be used. So if you consider the use of the lower version, you need to use fill_parent.
3, Wrap_content:
Setting the size of a view to Wrap_content will force the view to expand to show the entire content.
Android's Unit differences:
px:
PX is pixel, and 1px represents a physical pixel point on the screen. PX units are not recommended for use
DP:
Before introducing this unit, let's first look at the pixel density. Given a cell phone with a physical size of 1.5 inches x2 inches and a screen resolution of 240x320, we can calculate the number of pixels per inch on the screen of this phone as 240/1.5=160dpi (landscape) or 320/2=160dpi (portrait), 160DPI is the pixel density of this phone, and the pixel density unit dpi is the abbreviation for dots per inch, which is the number of pixels. This value is the same for both landscape and portrait, because most phone screens use a square pixel point.
Different cell phones/tablets may have different pixel densities. The Android system defines several pixel densities: low (120DPI), Medium (160DPI), High (240DPI), ultra-high (320DPI), ultra-high (480DPI), ultra-ultra-high (640DPI), and their corresponding DP-to-PX coefficients are 0.75, 1, 1.5, 2, 3, 4, this factor multiplied by the DP length is the number of pixels. For example, the interface has a length of "100dp" picture, then it is actually displayed as 100x1.5=150px on the 240dpi mobile phone, on the 320dpi phone actually displayed as 100x2=200px. If you compare these two phones together, you'll find that the physical size of the picture is "almost", which is the effect of using DP as a unit.
Dip:
Dip and DP are exactly the same, just different names. The dip was used in earlier versions of Android, and it was later recommended to use DP for unification with SP.
SP:
SP and DP are similar, but have a unique difference:
The Android system allows users to customize the font size (small, normal, large, oversized, etc.) when the size is "normal" when 1sp = 1DP = 0.00625 inches, and when the size is "large" or "oversized", 1sp > 1DP = 0.00625 inches. Similar to what we did after adjusting the font size in Windows-the window size is constant, only the text size changes.
Use occasions:
Google's official documentation suggests: the size of the text is used in SP units, non-text dimensions are used DP units . For example textsize= "16sp", layout_width= "60DP "
Occasionally you need to use PX units, such as when you need to draw a thin divider line on the screen: <view layout_width= "match_parent" layout_height= "1px"/>
Android Learning layout (top)