First, about the layout
- Layouts are containers for placing controls
- Layouts can be nested, so complex interface implementations can be done with layouts
Ii. Overview of 4 layout methods
- LinearLayout: Linear layout, very common
- Relativelayout: Relative layout, very common
- Framelayout: The frame layout, the application scenario is much less than linearlayout and relativelayout
- Tablelayout: Table layout, not commonly used
Three, linearlayout need to pay attention to the place
1, regarding the layout direction, because is linear, therefore has the direction, in the layout page through the Android:orientation property to set
- Vertical direction: android:orientation= "Vertical"
- Horizontal direction: android:orientation= "Horizontal"
2, about easy to confuse the two attributes:
- Android:layout_gravity: Specifies how the control is aligned in the layout
- Android:gravity: Specifies how the text in the control is aligned in the control
3, about the self-adaptation and Android:layout_weight properties
- The Android:layout_weight property allows us to use proportional methods to specify the size of the control, which plays a very important role in the adaptation of the screen
Four, relativelayout although the use of a lot of properties, but summed up there are three categories
- Reference object with Parent layout: Layout_alignparentleft | Layout_alignparentright | Layout_alignparenttop | Layout_alignparentbottom | Layout_centerinparent
- To reference an object with a control: Layout_above | Layout_below | Layout_toleftof | Layout_torightof
- Reference object to the edge of a control: Layout_alignleft | Layout_alignright | Layout_aligntop | Layout_alignbottom
Five, framelayout layout is very strange, it does not have any positioning method, all the controls will be placed in the upper left corner of the layout, which is the layout of the application scenario?
Six, tablelayout need to pay attention to the place
- Use <TableRow></TableRow> to specify row nodes;
- The column is not specified, as long as a control is added to the TableRow, a column is added;
- The control in TableRow cannot specify a width, and the Android:stretchcolumns property solves the problem
- If the number of columns in a row is not the same as the other rows, merge the cells with the Android:layout_span property
Example code for Tablelayout
<Tablelayoutxmlns:android= "Http://schema.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:stretchcolumns= "1" > <TableRow> <TextViewAndroid:layout_height= "Wrap_content"Android:text= "Account:" /> <EditTextAndroid:layout_height= "Wrap_content"Android:hint= "Input your account" /> </TableRow> <TableRow> <TextViewAndroid:layout_height= "Wrap_content"Android:text= "Password:" /> <EditTextAndroid:layout_height= "Wrap_content"Android:inputtype= "Textpassword" /> </TableRow> <TableRow> <ButtonAndroid:id= "@+id/login"Android:layout_height= "Wrap_content"Android:layout_span= "2"Android:text= "Login" /> </TableRow></Tablelayout>
"Android first line code" learning record 007-4 basic layouts