There are several common layouts available in Android:
LinearLayout
Linear layoutRelativeLayout
Relative to the layoutFrameLayout
The frame layoutAbsoluteLayout
Absolute layoutTableLayout
Table layoutGridLayout
Grid layout
Table elayout TableLayout
The introduction of TableLayout
TableLayout is a layout View container that arranges subclasses into rows and columns. The TableLayout is made up of a number of TableRow objects. The TableLayout manages child controls in the form of rows and columns, each cell being a TableRow or View object.
The setConlumnShrinkable() or setConlumnStretchable() methods can be used to specify columns that can be shrunk or stretchable. Columns are counted from 0, the first column being 0.
attribute
Several commonly used properties:
Android :stretchColumns=”2,3″ indicates that the stretchColumns are empty. If you want all columns to be empty, use *.
ShrinkColumns: Sets the sequence number of columns to be shrunk. ShrinkColumns are used when there are too many columns in a row or the content of a column is too long, causing the content of a column to be squeezed out of the screen.
Android :collapseColumns specifies the number of columns that need to be hidden. Use this property to hide a column.
Android :layout_column is the column in which the subclass control is displayed. Android :layout_column=”2″ means to skip the second and display directly in the third cell.
Android: layout_SPAN specifies the number of columns to occupy for the subclass control. Android :layout_span=”3″ means merge three cells, that is, this component will occupy three cells.
CollapseColumns hidden columns
The effect is as follows:
Android :collapseColumns = “0,2”, used to hide the first and third columns as follows:
<TableLayout
android:id="@+id/TableLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:collapseColumns="0, 2" >
<TableRow>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="one" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="two" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="three" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="four" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="five" />
</TableRow>
</TableLayout>
Copy the code
StretchColumns tensile column
Android :stretchColumns = “1”, set the stretchColumns to the stretchable column in the second column, fill the remaining space of the row, i.e. in the case of the parent width, put a few buttons, the remaining space will be filled by the second column, as shown below:
<TableLayout
android:id="@+id/TableLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="1" >
<TableRow>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="one" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="two" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="three" />
</TableRow>
</TableLayout>
Copy the code
ShrinkColumns contraction column
Android :shrinkColumns=”1″ Indicates that the second column is shrinkable. If the screen width is too large, the second column is shrinkable. Modify the code as above, add more content, make the text content off the screen!
GridLayout GridLayout
GridLayout is a new layout mode introduced in Android 4.0. It is similar to a table layout, but better than a table layout. It is also very powerful. How many rows, how many columns.
Property of that thing
Android: Orientation This parameter is used to set vertical or horizontal.
Android :layout_gravity is used to set the alignment, you can set center,right,left, etc.
Android :rowCount specifies the number of rows that can be set. For example, android:rowCount=”2″ specifies the number of rows that can be set.
Android :columnCount indicates the number of columns that can be set. For example, android:columnCount=”2″ indicates that the grid layout has 2 columns.
Android :layout_row is set to the number of lines on which the component is located, counting from 0, such as Android :layout_row=”1″ to set the component on line 2.
Android :layout_column sets the number of columns in which the component is located, counting from 0. For example, Android :layout_column=”1″ sets the component in the second column.
Android :layout_rowSpan sets the component to span several rows. For example, Android :layout_rowSpan=”2″ sets the component to span two rows vertically.
Android :layout_columnSpan indicates that the component spans several columns. For example, android:layout_columnSpan=”2″ indicates that the component spans two columns.
** Note: ** How does the lower SDK use GridLayout? Gridlayout > GirdLayout > GridLayout > GirdLayout
<android.support.v7.widget.GridLayout>
Copy the code
FrameLayout frame layout
What does FrameLayout FrameLayout look like? A layout in which all child controls are placed in the upper left corner and the following elements are directly overlaid on top of the preceding elements.
Common attributes:
Foreground image is always at the top of the frame layout container, which is not covered by the picture.
Android: foregroundGravity to set the position of the foreground image display.
The example code
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/FrameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="200dp"
android:layout_height="200dp"
android:background="#FF6143" />
<TextView
android:layout_width="150dp"
android:layout_height="150dp"
android:background="#7BFE00" />
<TextView
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#FFFF00" />
</FrameLayout>
Copy the code
The frame layout can be used to create a neon light effect by setting layout_gravity=”center” for each TextVeiw to see different effects.
AbsoluteLayout AbsoluteLayout
The AbsoluteLayout layout sets the location of child controls via x, Y positions, namely android:layout_x and Android: layout_Y properties.
Because absolute layout is not common and is not commonly used, it is not recommended to use it because the position will change intuitively on different sizes of adaptation screens.
RelativeLayout RelativeLayout
RelativeLayout is a RelativeLayout view group that displays RelativeLayout subview classes. By default, all subview pairs are distributed in the upper left corner.
Here’s a quick review of the related attributes:
Android :layout_above android:layout_toLeftOf Android :layout_toLeftOf android:layout_toLeftOf Android :layout_toRightOf is to the right of a control and is marked with id
Android :layout_alignBottom alignbottom to align with the bottom of a control, marked with id android:layout_alignTop to align with the top of a control, Android :layout_alignLeft alignleft with the left edge of a control. Android :layout_alignRight alignright with the right edge of a control
Android :layout_alignBaseline is in line with the text content of a control
Android :layout_alignParentBottom is true or false at the bottom of the parent container. True or false Android :layout_alignParentLeft is true or false in the parent container leftmost Android :layout_alignParentRight is true or false in the parent container rightmost
Android :layout_marginTop is the distance from the top of the parent container in dp android:layout_marginBottom is the distance from the bottom of the parent container, The unit is dp android:layout_marginLeft is the distance from the left of the parent container, and the unit is dp android:layout_marginRight is the distance from the right of the parent container, Android :layout_margin is the distance around the parent container, in dp
Android :layout_centerVertical: true or false android:layout_centerHorizontal: true or false True or false Android :layout_centerInParent is centered horizontally and vertically in the parent class
conclusion
Linear layout: The arrangement of child controls horizontally or vertically.
Relative layout: The arrangement of child controls in relation to each other or with respect to the parent container.
Frame layout: All child controls are placed in the upper left corner and the following element is directly overlaid by the preceding element.
Absolute layout: The placement of child controls by absolute positioning x and Y positions.
Table layout: Placing child controls in rows, each row containing a TableRow object or View object.
conclusion
- TableLayout, GridLayout, FrameLayout FrameLayout, AbsoluteLayout, RelativeLayout
- So I’m going to continue with this
Java
,Android
Other knowledge in depth, interested can continue to pay attention to - A small gift to walk or praise