5 Layouts in Android

Source: Internet
Author: User

1, LinearLayout

The default orientation is horizontal

Note the relationship between android:orientation= "horizontal" and android:layout_gravity= "" in Match_parent or wrap_content

Layout_gravity operation is the layout of the component gravity= "right" is the component's contents

2, Relativelayout

Child controls are independent of each other and are left-aligned by default

Android:layout_centerhorizontal= "true"

Android:layout_centervertical= "true"

Android:layout_centerinparent= "true"

Android:layout_alignparentleft= "true"

android:layout_toleftof= "@id/center"

android:layout_below= "@id/center"

3, Framelayout

Because there is no direction, so android:layout_gravity= "bottom" up or down can be effective

Note: Framelayout must be used in Tabhost

4, Tablelayout

Tablelayout in android:stretchcolumns= "1": Specify which column stretches to fill the remaining space

The columns in the Tablelayout are aligned by default

TableRow represents a row, and several child nodes represent a few columns

The immediate child nodes of the tablelayout default layout_width= "Match_parent" and layout_height= "wrap_content" and cannot be modified

The immediate child nodes of the TableRow default layout_height= "Wrap_content" and Layout_width= "wrap_content" and cannot be modified

layout_column= "1" sets the current component to the first column

layout_span= "2" current column occupies two columns of space

5, Absolutelayout Absolute layout

Layout_x and Layout_y Specify where the space is located

When you do not need to do a screen fit for a platform or a device, you may use

Demo
<tablelayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools "android:layout_width=" match_parent "android:layout_height=" Match_parent "Android:stret chcolumns= "1" tools:context= ". Mainactivity "> <TableRow> <textview android:layout_column=" 1 "android:text=" O Pen "/> <textview android:gravity=" right "android:text=" Ctrl-c "/> </tablerow&    Gt <TableRow> <textview android:layout_column= "1" android:text= "Save"/> <         TextView android:gravity= "Right" android:text= "Ctrl."/> </TableRow> <TableRow>            <textview android:layout_column= "1" android:text= "Save as:"/> <textview Android:gravity= "Right" android:text= "Ctrl-shift"/> </TableRow> <textview an Droid:layout_height= "1DP" android:background= "#000000"/> <TableRow> <textview android:text= "X"/> <textview android:layout_span= "2" android:text= "import"/> </TableRow> &lt ; tablerow> <textview android:text= "X"/> <textview android:text= "Export"/> <textvie W android:gravity= "right" android:text= "Ctrl"/> </TableRow> <textview Android oid:layout_height= "1DP" android:background= "#000000"/> <TableRow> <textview Andro id:layout_column= "1" android:text= "Qut"/> </TableRow></TableLayout>

Effect:


5 Layouts in Android

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.