Android "layout manager Syntax" Four big layouts "linearlayout,tablelayout,framelayout,relativelayout"

Source: Internet
Author: User

LinearLayout

A linear layout is the layout of the components that are placed in the vertical (vertical) or horizontal (horizontal) direction.

Which is to control the arrangement of the components horizontally or vertically. In a linear layout

Each line can have only one component for vertical arrangement or for horizontal arrangement for each column

。

Note: The Android linear layout does not wrap when the component is arranged next to the edge of the form.

The rest of the components will not show up


The arrangement is controlled by the Android:orientation property, and the alignment is controlled by the Android:gravity property.

(1) Common properties:

Android:orientation, Android:gravity,

Layout_width, Layout_height,

Androud:id,android:background


The first two are the properties supported by the linear layout manager,

The latter four are Android.view.View and Android.view.ViewGroup supported properties

Android:orientation Property

Used to set the arrangement of components within the layout manager, with optional values of horizontal (horizontal), vertical "default"(vertical)


Android:gravity Property

Lets you set the alignment of components within the layout manager, with optional values: Top, Bottom,left,right,center_vertical,fill_vertical,center_horizontal,fill_horizontal, Center,fill,clip_vertical,clip_horizontal

These values can be set at the same time by separating the middle |. For example, to specify that the component is aligned to the lower-right corner, you can use the Reight|bottom


android:layout_weight is an XML attribute supported by Viewgroup.layoutparams

The Fill_parent,match_parent,wrap_content property is used to set the base width of the component, with an optional value of match_parent ( recommended for use from Android2.2 ) and _ The role of the parent is exactly the same as "indicates that the component is the same width as the father and container."

Wrep_content indicates that the component's width fits neatly into his content.

Android:layout_height

Similar to the android:layout_weight



Tablelayout

A table layout is similar to a common table, which manages the UI components that are placed in rows and columns. Table layouts are defined using the <TableLayout></TableLayout> tag,

In the table, you can add multiple <TableRow> tags, one for each <TableRow> tag, and because the <TableRow> tag is also a container, you can add

Other components, in the <TableRow> tag, the table adds a column for each component that is added.

In a table layout, you can hide or extend a column by setting it.

This fills the available screen space, or you can set the force contraction until the table matches the screen size.


Tablelayout

Inherits LinearLayout, so it supports all XML attributes supported by LinearLayout, and Tablelayout has some special properties:

Android:stretchcolumns sets the sequence number of the column that needs to be hidden (sequence starts at 0), and multiple column ordinals are separated by commas

Android:shrinkcolumns sets the number of columns that are allowed to be shrunk (sequence starts from 0), and multiple column ordinals are separated by commas

Android:stretchcolumns sets the number of columns that are allowed to be stretched (the sequence starts at 0), and multiple column ordinals are separated by commas


<?xml version= "1.0" encoding= "Utf-8"? ><tablelayout xmlns:android= "http://schemas.android.com/apk/res/    Android "android:id=" @+id/tablelayout1 "android:layout_width=" match_parent "android:layout_height=" Match_parent " android:background= "@drawable/loginbg" android:gravity= "center_vertical" android:stretchcolumns= "0,3" > &lt ;! --First line--<tablerow android:id= "@+id/tablerow1" android:layout_width= "Wrap_content" Android            : layout_height= "wrap_content" > <textview/> <textview android:id= "@+id/textview1" Android:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:text= "Username:            "/> <edittext android:id=" @+id/edittext1 "android:layout_width=" Wrap_content "        android:layout_height= "Wrap_content" android:minwidth= "200px" android:textsize= "24px"/> <textview/> </tableRow> <!--second line--<tablerow android:id= "@+id/tablerow2" android:layout_width= "wrap_content "android:layout_height=" wrap_content "> <textview/> <textview android:id=" @+ Id/textview2 "android:layout_width=" wrap_content "android:layout_height=" Wrap_content "an            droid:text= "Password" android:textsize= "24px"/> <edittext android:id= "@+id/edittext2" Android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" Android:inputtype= "Tex Tpassword "android:minwidth=" 200px "android:textsize=" 24px "/> <textview/> </ tablerow> <tablerow android:id= "@+id/tablerow2" android:layout_width= "Wrap_content" Android: layout_height= "Wrap_content" > <textview/> <textview/> <button Android      : id= "@+id/button1"      Android:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:text= "Login" Android:textsize= "24px"/> <textview/> </TableRow></TableLayout>




Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android "layout manager Syntax" Four big layouts "linearlayout,tablelayout,framelayout,relativelayout"

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.