Android layout is an important part of application interface development, in Android, there are five kinds of layout methods, namely: LinearLayout (Linear layout), Framelayout (frame layout), Absolutelayout (absolute layout), Relativelayout (relative layout), tablelayout (table layout).
First, linear layout
Linear layout. 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. LinearLayout has an important attribute android:layout_weight= "1", weight is called weight, several controls within a container if the weights are set to 1, then the size of several tools should be equal. If a weight is 2 the other weight is 1, it does not mean that its corresponding control is twice times the size.
<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "vertical" > <EditTextAndroid:layout_weight= "1"Android:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"Android:text= "@string/hello_world" /> <EditTextAndroid:layout_weight= "1"Android:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"Android:text= "@string/hello_world" /> <LinearLayoutAndroid:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"android:orientation= "Horizontal"Android:layout_weight= "2" > <EditTextAndroid:layout_weight= "1"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent"Android:text= "@string/hello_world" /> <EditTextAndroid:layout_weight= "1"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent"Android:text= "@string/hello_world" /> </LinearLayout></LinearLayout>
Second, framelayout
Framelayout is one of the simplest layout objects. The latter child element will overwrite the padding directly above the previous child element, blocking them partially or completely (unless the latter element is transparent).
<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "vertical"Android:layout_margintop= "50DP" > <FramelayoutAndroid:layout_width= "Fill_parent"Android:layout_height= "Wrap_content" > <ImageViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:layout_gravity= "Center"android:src= "@drawable/moive" /> <ImageViewAndroid:layout_width= "35DP"Android:layout_height= "35DP"Android:layout_marginleft= "80DP"Android:layout_margintop= "80DP"android:src= "@drawable/play" /> </Framelayout> <LinearLayoutAndroid:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"android:orientation= "Horizontal" > <ButtonAndroid:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"Android:layout_weight= "1"Android:text= "Paused" /> <ButtonAndroid:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"Android:layout_weight= "1"Android:text= "Play" /> </LinearLayout></LinearLayout>
Third, table layout
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 defines a row (in fact, you can define other sub-objects, which are explained below). 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. Cells cannot span columns, which is not the same as in HTML.
<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "vertical"Android:layout_margintop= "50DP" > <TablelayoutAndroid:layout_width= "Fill_parent"Android:layout_height= "Fill_parent" > <TableRow> <ImageViewAndroid:layout_width= "35DP"Android:layout_height= "35DP"android:src= "@drawable/play"Android:layout_weight= "1" /> <ImageViewAndroid:layout_width= "35DP"Android:layout_height= "35DP"android:src= "@drawable/play"Android:layout_weight= "1" /> </TableRow> <TableRow> <ImageViewAndroid:layout_width= "35DP"Android:layout_height= "35DP"android:src= "@drawable/play"Android:layout_weight= "1" /> <ImageViewAndroid:layout_width= "35DP"Android:layout_height= "35DP"android:src= "@drawable/play"Android:layout_weight= "1" /> </TableRow> </Tablelayout> </LinearLayout>
Four, absolute layout, is to determine the position of the control by XY coordinates
<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "vertical" > <AbsolutelayoutAndroid:layout_width= "Fill_parent"Android:layout_height= "Fill_parent" > <ImageViewAndroid:layout_width= "35DP"Android:layout_height= "35DP"android:src= "@drawable/play"android:layout_x= "50DP"android:layout_y= "50DP" /> </Absolutelayout></LinearLayout>
Vi. Relative layout
The relative layout of the child controls is relative layout based on the reference controls and parameters that they set. The reference control can be either a parent control or another child control, but the referenced control must be defined before the control that references it. The following is a simple example:
<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "vertical" > <RelativelayoutAndroid:layout_width= "Match_parent"Android:layout_height= "Match_parent" > <ImageViewAndroid:id= "@+id/top_name"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_torightof= "@id/head_name"android:src= "@drawable/top" /> <ImageViewAndroid:id= "@+id/head_name"Android:layout_width= "130DP"Android:layout_height= "130DP"android:src= "@drawable/head" /> <ImageViewAndroid:id= "@+id/play_name"Android:layout_width= "80DP"Android:layout_height= "80DP"android:src= "@drawable/play"Android:layout_torightof= "@id/head_name"Android:layout_below= "@id/top_name" /> </Relativelayout></LinearLayout>
Android Five layout modes