One: LinearLayout
1, linear layout, this thing, from the outer frame can be understood as a Div, he first is a list from the top down on the screen. Each of the linearlayout can be divided into vertical layouts (android:orientation= "vertical") and horizontal layouts (android:orientation= "horizontal"). When vertical layout, there is only one element for each row, and multiple elements are descending vertically; when horizontal layout, there is only a row, and each element is arranged to the right.
There is an important attribute android:layout_weight= "1" in the LinearLayout, which represents the line spacing when vertical layout, the column width when horizontal, the larger the weight value.
2, TextView accounted for a certain space, there is no assignment is also a certain width, to pay special attention.
First Instance
:
Code:
<?xml version= "1.0" encoding= "Utf-8"?> <linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"android:orientation= "Vertical"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent" > <LinearLayout android:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"android:orientation= "Vertical" > <EditText android:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"/> </LinearLayout> <LinearLayout android:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"android:orientation= "Horizontal"android:gravity= "Right" > <!--android:gravity= "OK" means that the button component is aligned to starboard-<Button android:layout_height= "Wrap_content"Android:layout_width= "Wrap_content"Android:text= "OK"/> <Button android:layout_height= "Wrap_content"Android:layout_width= "Wrap_content"Android:text= "Cancel"/> </LinearLayout> </LinearLayout>
A second example:
:
Code:
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "Vertical" ><TextView android:layout_width= "Match_parent"Android:layout_height= "0DP"Android:layout_weight= "5"Android:background= "#3C3C3C"/><TextView android:layout_width= "Match_parent"Android:layout_height= "0DP"Android:layout_weight= "1"Android:background= "#FFEFD5"/> <LinearLayout android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:layout_weight= "4"Android:background= "#66CDAA"android:orientation= "Horizontal" > <TextView Android:id= "@+id/txt1"Android:layout_width= "Wrap_content"Android:layout_height= "Match_parent"Android:background= "#FFF663"Android:layout_weight= "1"/> <TextView Android:id= "@+id/txt2"Android:layout_width= "Wrap_content"Android:layout_height= "Match_parent"Android:background= "#E82917"Android:layout_weight= "4"/> <TextView Android:id= "@+id/txt3"Android:layout_width= "Wrap_content"Android:layout_height= "Match_parent"Android:background= "#FFF663"Android:layout_weight= "1"/> </LinearLayout></LinearLayout>
All we have to do is practice more and look at the layout of the software. The layout of the software and the layout of the real machine are different, we try to take the real machine to test, and on different models to go to test.
Android Development--layout