First, LinearLayout
Linear layout, this thing, from the outer frame can be understood as a div, it is first 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.
TextView occupies a certain space, there is no assignment also has a certain width high.
Second, framelayout
Framelayout is one of the simplest layout objects. It is customized as a blank alternate area on your screen, after which you can populate a single object-for example, a picture you want to publish. All child elements will be pinned to the upper-left corner of the screen; You cannot specify a location for a child element in Framelayout. The next child element will overwrite the padding directly above the previous child element, blocking them partially or completely.
Third, Absolutelayout
Absolutelayout This layout is simple, the main properties of the two layout_x and layout_y respectively define the absolute position of this component. That is, the X, y value of the axis (0,0) in the upper-left corner of the screen, when moving down or to the right, the coordinate value becomes larger. Absolutelayout does not have a page border, allowing elements to overlap each other. Absolutelayout is not usually recommended by other developers because it makes the interface code too rigid that it may not work well on different devices.
Iv. Relativelayout
The relative layout can be understood as the layout of an element as a reference object.
Android:layout_ Direction = ID indicates the direction of the control corresponding to this ID (top | down)
Android:layout_align Direction = ID representation and alignment of the control (up or down)
Android:layout_to direction of = ID indicates the left or right of the control
android:layout_below= "@id/la1"/place the current control under the control with the ID la1.
android:layout_alignparentright= true to align the right end of the current control with the right end of the parent control. This property value can only be true or FALSE, the default
android:layout_marginleft= "10dip" causes the current control to empty out of space on the left.
android:layout_toleftof= "@id/true" causes the current control to be placed to the left of the control with ID true.
android:layout_aligntop= "@id/ok" aligns the current control with the upper end of the control with the ID OK.
Wu, Tablelayout
The table layout is similar to the table in HTML. Each of the tablelayout has a table row Tablerow,tablerow inside can define each element in detail. Each TableRow will define a row. The Tablelayout container does not display the row, cloumns, or cell border lines. Each row has 0 or more cells, and each cell has a view object. A table consists of columns and rows that make up many cells. Table allows cells to be empty.
Each layout has its own appropriate way, and these five layout elements can be nested within each other to make an aesthetically pleasing interface.
1 linear layout (linearlayout)
<?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" >
<button android:text= "Up"
Android:id= "@+id/button03"
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content" ></Button>
<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
android:orientation= "Horizontal"
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent" >
<button android:text= "left"
Android:id= "@+id/button01"
Android:width= "120px"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content" ></Button>
<button
Android:text= "Right"
Android:id= "@+id/button02"
Android:width= "120px"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content" ></Button>
</LinearLayout>
</LinearLayout>
2. Table layout (tablelayout)
<?xml version= "1.0" encoding= "Utf-8"?>
<tablelayout
Xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:id= "@+id/tablelayout01"
Android:layout_width= "Fill_parent" android:layout_height= "Fill_parent" >
<tablerow android:gravity= "center" >
<button
android:text= "@+id/button01"
Android:id= "@+id/button01"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content" >
</Button>
</TableRow>
<tablerow android:gravity= "center" >
<textview android:text= "First row No. 0 column"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content" ></TextView>
<textview android:text= "First row 1th column"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content" ></TextView>
</TableRow>
<tablerow android:gravity= "center" >
<textview android:text= "second row No. 0 column"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content" ></TextView>
<textview android:text= "second row 1th column"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content" ></TextView>
</TableRow>
</TableLayout>
3. Single frame layout (framelayout)
<?xml version= "1.0" encoding= "Utf-8"?>
<framelayout
Xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content" >
<imageview
Android:id= "@+id/imageview01"
android:src= "@drawable/circle_blue"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content" >
</ImageView>
<imageview
Android:id= "@+id/imageview02"
android:src= "@drawable/circle_green"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content" >
</ImageView>
<imageview
Android:id= "@+id/imageview03"
android:src= "@drawable/circle_red"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content" >
</ImageView>
</FrameLayout>
4. Relative layout (relativelayout)
Common properties: android:layout_centerinparent= "True/false"
Android:layout_above, Android:layout_below
Android:layout_alignleft, Android:layout_alignright.
<?xml version= "1.0" encoding= "Utf-8"?>
<relativelayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:layout_width= "Fill_parent" android:layout_height= "Fill_parent" >
<button
Android:id= "@+id/btnmiddle"
android:text= "Middlebutton"
Android:layout_width= "200px"
android:layout_height= "Wrap_content"
Android:layout_centerinparent= "true" >
</Button>
<button
Android:id= "@+id/btnup"
android:text= "UpButton"
Android:layout_width= "100px"
android:layout_height= "Wrap_content"
Android:layout_above= "@id/btnmiddle"
android:layout_alignleft= "@id/btnmiddle" >
</Button>
<button
Android:id= "@+id/btndown"
android:text= "DownButton"
Android:layout_width= "100px"
android:layout_height= "Wrap_content"
android:layout_below= "@id/btnmiddle"
android:layout_alignright= "@id/btnmiddle" >
</Button>
</RelativeLayout>
5. Absolute layout (absolutelayout)
Common properties: android:layout_x,android:layout_y.
In my learning process of Android development, I used a lot of relative layout and linear layout, and seldom used absolute layout and frame layout. In the process of writing the calculator app, the layout of the table helped me to layout easily, so mastering these 5 basic layouts is a great way to improve efficiency in Android development. Now re-review the Android layout, feeling very rewarding.
Android Layout Learning Notes