Several common layouts are available in Android:
LinearLayout
Linear layout
RelativeLayout
Relative layout
FrameLayout
Frame layout
AbsoluteLayout
Absolute layout
TableLayout
Table layout
GridLayout
Grid layout
Tablelayout Table Layout
Introduction of Tablelayout
TableLayout
is a layout view container that arranges subclasses into rows and columns, TableLayout
is TableRow
composed of many objects, and the table layout manages the child controls in the form of rows and blocks, each of which is one TableRow
or View
object.
In the TableLayout
or method in which you can setConlumnShrinkable()
specify that setConlumnStretchable()
certain columns can be scaled down or scalable, the column is counted from 0, and the first is 0.
Property
Several commonly used properties:
stretchColumns
To set the sequence number of the column that is being stretched , as android:stretchColumns="2,3"
indicated in the third column and the fourth column, fill in the blanks, and if you want all columns to fill the blanks together, the “*”
column numbers are counted starting from 0.
shrinkColumns
To set the ordinal of a column that is shrunk, shrinkage is used for too many columns in a row, or the content text of a column is too long, causing the contents of a column to be squeezed out of the screen, a property that helps to shrink the contents of a column to prevent extrusion.
android:collapseColumns
To set the ordinal of a column that needs to be hidden , use this property to hide a column.
android:layout_column
For the sub-class control to be displayed in the first column . android:layout_column="2"
indicates that the second one is skipped and is displayed directly in the third cell.
android:layout_span
The number of columns to occupy for the subclass control . android:layout_span="3"
represents a merge of 3 cells, which will occupy 3 cells.
Collapsecolumns Hidden columns
Effect
android:collapseColumns = "0,2"
To hide the first and third columns with the following code:
<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>
Stretchcolumns Stretching columns
android:stretchColumns = “1”
, set to the second column to stretch the column, so that the column fills all the remaining space in the row, that is, in the case of the entire parent width, put a few buttons, the remaining space width will be filled with the second column, the code is as follows:
<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>
Shrinkcolumns Shrinking columns
android:shrinkColumns="1"
Indicates that the contents of the second column are shrunk, if the width of the screen is not inclusive, the second column will be shrunk, that is, flattened, elongated. Like the code to modify, add more content, so that its text content beyond the screen bar!
GridLayout Grid Layout
GridLayout
Grid layout is a Android 4.0
new layout pattern introduced in the future, and table layout is a bit similar, but better than the table layout, the function is also very powerful, it can set the layout of how many rows and how many columns, you can set the layout of the components of the arrangement, you can also set the location of the component, across how many rows, how many columns.
property of that little thing
android:orientation
Used to set vertical
vertical or horizontal
horizontal.
android:layout_gravity
To set the alignment , you can set center,right,left
and so on.
android:rowCount
To set the number of rows, how many rows you want to set, such as android:rowCount="2"
2 rows for setting the grid layout.
android:columnCount
For the number of columns you can set, how many columns you want to set, such as android:columnCount="2"
2 columns for setting the grid layout.
android:layout_row
For the set component on the first line , count from 0, as set the android:layout_row="1"
component on line 2nd.
android:layout_column
For the set component in the number of columns, starting from 0 counts, as android:layout_column="1"
set for the component in column 2nd.
android:layout_rowSpan
sets the components across several lines , such as android:layout_rowSpan="2"
vertical spans of 2 rows.
android:layout_columnSpan
sets the component across several columns , such as android:layout_columnSpan="2"
horizontal across 2 columns.
Caveats: How is the low version SDK used? GridLayout
To import the package of the V7 package gridlayout
, because GirdLayout
it is 4.0 after the release of the tag code.
<android.support.v7.widget.GridLayout>
Framelayout Frame Layout
FrameLayout
What is the frame layout like? All child controls are placed in the upper-left corner and subsequent elements are directly covered by a layout pattern above the preceding element.
Common Properties:
android:foreground
To set the foreground image for the frame-changing layout container , what is the foreground image, the foreground image is always the topmost image of the frame layout container, or the picture that will not be overwritten.
android:foregroundGravity
the location to display for setting the foreground image .
Code
<FrameLayoutxmlns: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>
With the frame layout you can make the neon effect, that is, for each TextVeiw
setting layout_gravity="center"
, you can see a different effect.
Absolutelayout Absolute Layout
AbsoluteLayout
An absolute layout is a x,y
property that sets the location of a child control by its location android:layout_x和android:layout_y
.
Because the absolute layout is not common, not commonly used, because the position on the different size of the adaptation screen will change intuitively, poor adaptability, so it is not recommended.
Relativelayout Relative layout
RelativeLayout
is a relative layout of the view group that displays the relative position of the child view class, by default, all child view pairs are distributed in the upper-left corner.
Simply review the relevant properties here:
android:layout_below
To be located below a control , mark with ID
android:layout_above
To be located above a control , mark with ID
android:layout_toLeftOf
To the left of a control , marked with an ID
android:layout_toRightOf
To the right of a control , mark with ID
android:layout_alignBottom
To align with the bottom of a control , mark with ID
android:layout_alignTop
To align with the top of a control , mark with ID
android:layout_alignLeft
To align with the left edge of a control , mark with ID
android:layout_alignRight
To align to the right edge of a control , mark with ID
android:layout_alignBaseline
For the text content of a control in a straight line
android:layout_alignParentBottom
Is at the top of the parent container , true or False
android:layout_alignParentTop
To be the highest in the parent container , true or False
android:layout_alignParentLeft
To the left of the parent container , true or False
android:layout_alignParentRight
To the right of the parent container , true or False
android:layout_marginTop
is the distance from the top of the parent container , in units of DP
android:layout_marginBottom
is the distance from the lower end of the parent container , in units of DP
android:layout_marginLeft
is the distance from the left side of the parent container , in units of DP
android:layout_marginRight
is the distance from the right end of the parent container , in units of DP
android:layout_margin
is the distance from the parent container and the unit is DP
android:layout_centerVertical
is centered vertically in the parent class , True or False
android:layout_centerHorizontal
centered at the parent class , True or False
android:layout_centerInParent
To center horizontally vertically on the parent class
Conclusion
Linear layout:
Refers to child controls arranged horizontally or vertically .
Relative layout:
Refers to a child control arranged in a relative position between controls or on the position of a child control relative to the parent container .
Frame layout:
means that all child controls are placed in the upper-left corner and the following elements are directly above the preceding element .
Absolute layout:
A child control determines its position by absolutely locating the X, y position .
Table layout:
refers to placing child controls as rows and columns, each of which is a TableRow object or view object .
Conclusion
- This article mainly explains? Android Mastery: tablelayout layout, GridLayout grid layout, framelayout frame layout, absolutelayout absolute layout, Relativelayout relative layout
- Below I will continue to
Java
,? Android
In-depth explanation of other knowledge, and interested to continue to focus on
- A little gift to walk or like.
Android Mastery: tablelayout layout, GridLayout grid layout, framelayout frame layout, absolutelayout absolute layout, Relativelayout relative layout