Concept
Android is a variety of programs, relying on the layout, first to see how the layout is:
The white part is the layout that we often use, mainly say this
Linear layout-linearlayout
Aligns all elements in one direction.
can be horizontal, vertical, can also be nested, directly look at the code bar
<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent"android:orientation= "vertical" > <!--vertical stands for vertical layout - <TextViewAndroid:layout_width= "Fill_parent"Android:layout_height= "50dip"Android:background= "#88AAFF"android:gravity= "Center_horizontal"Android:text= "ABCDEFG"android:textsize= "14dip" /> <LinearLayoutAndroid:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "Horizontal" > <!--Horizontal represents landscape layout - <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "50dip"Android:layout_weight= "0"Android:background= "#22FFFF"Android:text= "Hello" /> <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "50dip"Android:layout_weight= "1"Android:background= "#FF22FF"Android:text= "World" /> <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "50dip"Android:layout_weight= "2"Android:background= "#2222FF"Android:text= "Ni" /> <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "50dip"Android:layout_weight= "3"Android:background= "#FFFF22"Android:text= "Hao" /> </LinearLayout></LinearLayout>
Based on the above layout and the results of the program run, you can get the following conclusions:
1, android:orientation= "vertical" stands for vertical layout horizontal represents landscape layout
2, android:gravity= "center_horizontal" This sentence makes the ABCDEFG center alignment
3, android:layout_weight= "0" This value determines the weight of the percentage of the screen
Program Run Result:
It seems that the linear layout is sufficient for the general requirements.
Relative layouts-relative layout
Heard is the layout of the most powerful function, it exists in order to adapt to a variety of screen resolution.
<Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent" > <AnalogClockAndroid:id= "@+id/aclock"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:layout_centerinparent= "true" /> <!--layout_centerinparent= "True" is centered, displaying the control in the middle of the parent window. - <DigitalClockAndroid:id= "@+id/dclock"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_alignleft= "@id/aclock"Android:layout_below= "@id/aclock"Android:layout_marginleft= "40px" /> <!--layout_alignleft= "@id/aclock" aligns the left edge of the control with the left edge of the given ID control android:layout_below= "@id/aclock" places the control in the given ID control Under Layout_marginleft defined controls the left margin is 40 dips - <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_aligntop= "@id/aclock"Android:layout_toleftof= "@id/dclock"Android:text= "Current time:" /> <!--android:layout_above= "@id/xxx" puts the control on top of the given ID control Android:layout_toleftof aligns the right edge of the control with the left edge of the given ID control -</Relativelayout>
According to the above comment, it is possible to know that the program is running like this:
Relative layout is really powerful, can be arranged at will, the following see some common relative layout uses the meaning of the property:
Android:layout_above= "@id/xxx" -puts the control on top of the given ID control
android:layout_below= "@id/xxx" -places the control under the given ID control
android:layout_toleftof= "@id/xxx" -aligns the right edge of the control with the left edge of the given ID control
android:layout_torightof= "@id/xxx" -aligns the left edge of the control with the right edge of the given ID control
android:layout_alignleft= "@id/xxx"-aligns the left edge of the control with the left edge of the given ID control
android:layout_aligntop= "@id/xxx" -aligns the top edge of the control with the top edge of the given ID control
android:layout_alignright= "@id/xxx"-Aligns the right edge of the control with the right edge of the given ID control
android:layout_alignbottom= "@id/xxx" -aligns the bottom edge of the control with the bottom edge of the given ID control
Android:layout_alignparentleft= "true"-aligns the left edge of the control with the left edge of the parent control
Android:layout_alignparenttop= "true" -aligns the top edge of the control with the top edge of the parent control
Android:layout_alignparentright= "true"-aligns the right edge of the control with the right edge of the parent control
Android:layout_alignparentbottom= "true" -aligns the bottom edge of the control with the bottom edge of the parent control
Android:layout_centerinparent= "true"--places the control in the center of the parent control
Android:layout_centerhorizontal= "true" --places the control in the center of the horizontal direction
Android:layout_centervertical= "true"--places the control in the center of the vertical direction
"Android Development Learning note", "Seventh lesson" layout-top