Android Mastery: tablelayout layout, GridLayout grid layout, framelayout frame layout, absolutelayout absolute layout, Relativelayout relative layout

Source: Internet
Author: User

Several common layouts are available in Android:

    1. LinearLayoutLinear layout
    2. RelativeLayoutRelative layout
    3. FrameLayoutFrame layout
    4. AbsoluteLayoutAbsolute layout
    5. TableLayoutTable layout
    6. GridLayoutGrid layout
Tablelayout Table Layout

Introduction of Tablelayout

TableLayoutis 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:

stretchColumnsTo 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.

shrinkColumnsTo 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:collapseColumnsTo set the ordinal of a column that needs to be hidden , use this property to hide a column.

android:layout_columnFor 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_spanThe 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

GridLayoutGrid 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:orientationUsed to set vertical vertical or horizontal horizontal.

android:layout_gravityTo set the alignment , you can set center,right,left and so on.

android:rowCountTo 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:columnCountFor 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_rowFor the set component on the first line , count from 0, as set the android:layout_row="1" component on line 2nd.

android:layout_columnFor 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_rowSpansets the components across several lines , such as android:layout_rowSpan="2" vertical spans of 2 rows.

android:layout_columnSpansets 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

FrameLayoutWhat 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:foregroundTo 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:foregroundGravitythe 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

AbsoluteLayoutAn 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

RelativeLayoutis 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_belowTo be located below a control , mark with ID
android:layout_aboveTo be located above a control , mark with ID
android:layout_toLeftOfTo the left of a control , marked with an ID
android:layout_toRightOfTo the right of a control , mark with ID

android:layout_alignBottomTo align with the bottom of a control , mark with ID
android:layout_alignTopTo align with the top of a control , mark with ID
android:layout_alignLeftTo align with the left edge of a control , mark with ID
android:layout_alignRightTo align to the right edge of a control , mark with ID

android:layout_alignBaselineFor the text content of a control in a straight line

android:layout_alignParentBottomIs at the top of the parent container , true or False
android:layout_alignParentTopTo be the highest in the parent container , true or False
android:layout_alignParentLeftTo the left of the parent container , true or False
android:layout_alignParentRightTo the right of the parent container , true or False

android:layout_marginTopis the distance from the top of the parent container , in units of DP
android:layout_marginBottomis the distance from the lower end of the parent container , in units of DP
android:layout_marginLeftis the distance from the left side of the parent container , in units of DP
android:layout_marginRightis the distance from the right end of the parent container , in units of DP
android:layout_marginis the distance from the parent container and the unit is DP

android:layout_centerVerticalis centered vertically in the parent class , True or False
android:layout_centerHorizontalcentered at the parent class , True or False
android:layout_centerInParentTo 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.