Android five big layout files

Source: Internet
Author: User

Android in order to accommodate a variety of layout formats, provides a 5 format of layout:

LinearLayout (linear layout) Framelayout (frame layout) Relativelayout (relative layout) Tablelayout (table layout) Absolutelayout ( Absolute Layout ).

In the Android project, we want to design a refreshing interface, all the use of these layout format. These layout files exist primarily in the format of an XML file and are saved in the/res/layout directory. This folder has a variety of layout files that we write. For example:/res/layout/activity_main.xml.

Let's look at 5 layout files in detail:

    1. Framelayout (Frame layout)

This layout is the simplest form of layout, and the added components are displayed in a cascading fashion, with the first control at the bottom, and the last control added at the top level of the view display, a bit like a stack. Here is an example of yourself:

 <?xml version= "1.0"  encoding= "Utf-8"? ><linearlayout xmlns:android= "http// Schemas.android.com/apk/res/android "    android:layout_width=" Match_parent "     android:layout_height= "Match_parent"     android:background= "@drawable/ Background "    android:orientation=" vertical " >    < Linearlayout        android:layout_width= "Match_parent"          android:layout_height= "300dip"          android:orientation= "Vertical"  >        <Button             android:id= "@+id/start"              android:layout_width= "Wrap_content"              android:layout_height= "Wrap_content"              android:text= "Startanimation"              />        <Button             android:id= "@+id/stop"              android:layout_width= "Wrap_content"              android:layout_height= "Wrap_content"              android:text= "Reversestartanimation"              />            </ linearlayout>    <!-- windmill layout -->     <relativelayout   &nbSp;    android:layout_width= "Match_parent"          android:layout_height= "Match_parent"  >        <framelayout             android:id= "@+id/windmill_layout"             android:layout_width= "Match_parent"             android:layout_height= "80dip"   >            <ImageView                 android:id= "@+id/im_roof"                  android:layout_width = "Wrap_content"                  android:layout_height= "WRAp_content "                 android:layout_gravity= "Center"                  android:src= "@drawable/windmill_roof"  />             <ImageView                 android:id= "@+id/im_fan"                  android:layout_width= "104DP"                  android:layout_height= "106DP"                  android:layout_gravity= "Center"                 android:src= "@ Drawable/windmill_fan " />        </framelayout>         <imageview            android:id= "@ +id/im_window "            android:layout_width=" 80dip "            android:layout_height=" 80dip "             android:layout_alignparentbottom= "true "            android:layout_centerhorizontal=" true "            android:layout_marginbottom=" 20DP "             android:src= "@drawable/windmill_window " />    </RelativeLayout></LinearLayout>

This is a framelayout layout nested in the relativelayout. And there are two overlapping ImageView objects in the framelayout layout.

2. Absolutelayout (Absolute layout)

The child controls in this layout need to specify the horizontal ordinate of the relative position of their coordinates, or the layout will be arranged in the upper-left corner like the framelayout layout. This layout does not automatically fit into the screen size, so use less, here is a brief description of the definition.

3.TableLayout (Table layout)

Definition: The handle element is placed in rows and columns, and the row and column lines and cell boundaries are not displayed. Each row is a TableRow, or it can be a view object. Add a control to the TableRow every day, representing a column.

Attribute parameter Description:

Android:layout_colum: Sets the column where the control is located in TableRow.

Android:layout_span: Sets the number of columns that this control spans.

Android:collapseColumns:TableLayout The specified column is hidden, multiple columns are hidden, and the comma separates the hidden classes.

Android:stretchcolumns: The specified column can be stretched, multiple columns stretched, separated by commas.

Android:shrinkcolmns: Sets the columns that are specified to be shrunk.

4.LinearLayout (Linear layout)

Definition: Aligns all child elements in one direction (vertical or horizontal), with only one child element for each row in a vertical list, and a horizontal list is just a column height.

<?xml version= "1.0"  encoding= "Utf-8"? ><linearlayout xmlns:android= "http// Schemas.android.com/apk/res/android "    android:layout_width=" Fill_parent "     android:layout_height= "Wrap_content"     android:gravity= "center_vertical"     android:orientation= "Vertical"  >    <TextView         android:id= "@+id/catalog"          android:layout_width= "Fill_parent"         android:layout_height= "Fill_parent"         android:background= "#E0E0E0"          android:textcolor= "#454545"          Android:layout_weight= "1.0"         android:paddingleft= "5dip"          android:paddingtop= "5dip"         android:paddingbottom= "5dip"          android:text= "A"/>    <textview         android:id= "@+id/title"          Android:layout_width= "Fill_parent"         android:layout_height= "Fill_ Parent "        android:layout_gravity=" center_vertical "         android:gravity= "Center_vertical"          android:layout_weight= "1.0"         android:textcolor= "# 336598 "        android:layout_marginleft=" 5dip "         android:paddingtop= "10dip"          Android:paddingbottom= "10dip"         android:text= "HHHH"/></linearlayout> 

5.RelativeLayout (relative layout)

Definition: Depending on the layout, the child controls are relatively laid out according to the reference controls and parameters that they set. The reference control can be either a parent control or another child control, but the referenced space must be defined before the control that references it.

<?xml version= "1.0"  encoding= "Utf-8"? ><relativelayout xmlns:android= "http// Schemas.android.com/apk/res/android "    android:id=" @+id/umeng_socialize_comment_item "     android:layout_width= "Fill_parent"     android:layout_height= "Wrap_ Content "    android:background=" #ffffff "    android:padding=" 5DP "  >    <!--  Avatar  -->    <RelativeLayout         android:id= "@+id/umeng_socialize_comment_item_profile_gp"          android:layout_width= "50DP"          android:layout_height= "130DP"         android:layout_ marginleft= "8DP"         android:gravity= "center"  >         <imagevIew            android:layout_width= "Fill_parent"             android:layout_height= "Fill_parent"             android:background= "@null"  />         <ImageView             android:id= "@+id/umeng_socialize_comment_avatar"              android:layout_width= "48DP"              android:layout_height= "48DP"              android:layout_margintop= "8DP"              android:layout_centervertical= "true"              android:src= "@drawable/umeng_socialize_default_avatar "             android:scaletype= "Fitxy"  />    </RelativeLayout>     <textview        android:id= "@+id/umeng_socialize_comment_ Item_name "        android:layout_width=" Wrap_content "         android:layout_height= "Wrap_content"          android:layout_marginleft= "8DP"         android:layout_ margintop= "5DP"         android:layout_torightof= "@id/umeng_socialize_ COMMENT_ITEM_PROFILE_GP "        android:ellipsize=" End "         android:ems= "Ten"         android: maxlines= "1"         android:textcolor= "@color/umeng_socialize_list_item_textcolor"          android:textsize= "14SP"          />     <!--  a123456789b123456789c123456789d123456789e123456789f123456789g123456789h123456789 -->     <textview        android:id= "@+id/umeng_socialize_comment_ Item_content "        android:layout_width=" Wrap_content "         android:layout_height= "Wrap_content"          android:layout_marginleft= "8DP"         android:layout_ margintop= "0DP"         android:layout_torightof= "@id/umeng_socialize_ COMMENT_ITEM_PROFILE_GP "        android:layout_below=" @id/UMeng_socialize_comment_item_name "        android:maxlength="          android:layout_marginright= "18DP"          android:scrollhorizontally= "false"         android: Ellipsize= "End"         android:textcolor= "#646464"          android:textsize= "12SP"  />    <TextView         android:id= "@+id/umeng_socialize_comment_item_time"          android:layout_margintop= "0DP"          android:layout_marginleft= "8DP"         android:layout_width= " Wrap_content "        android:layout_height=" Wrap_content "          android:layout_below= "@id/umeng_socialize_comment_item_content"          android:layout_torightof= "@id/umeng_socialize_comment_item_profile_gp"          android:textcolor= "@color/umeng_socialize_text_time"          android:textsize= "10SP"  />    <ImageView         android:id= "@+id/umeng_socialize_comment_item_has_location"         android:layout_margintop= "0DP"         android:layout _alignparentright= "true"         android:layout_centervertical= "true"         android:layout_height= "18DP"          android:layout_width= "18DP"         android:scaletype = "Fitxy" &NBSP;&NBSP;&NBSP;&NBSP;&Nbsp;   android:visibility= "Invisible"         android: src= "@drawable/umeng_socialize_location_ic"/>    </relativelayout>

The relative layout of the attribute parameters is more, but also more important layout format. Describe the property parameters of the Relativelayout layout:

Android:layout_centerhorizontal Horizontal Center

Android:layout_centervertical Vertical Center

Android:layout_centerinparent is completely centered relative to the parent element

Android:layout_alignparentbottom closer to the bottom edge of the parent element

Android:layout_alignparentleft

Android:layout_alignparentright

Android:layout_alignparenttop

android:layout_alignwithparentifmissing if the corresponding sibling element is not found, the parent element is used as a reference

android:layout_below= "Id/id-name" under an element

Android:layot_top

Android:layout_toleftof

Android:layout_torightof

Android:layout_aligntop aligns the top edge of this element with the top edge of an element

Android:layout_alignbottom

Android:layout_alignleft

Android:layout_alignright

Android:layout_marginbottom distance from the bottom edge of an element

Android:layout_margintop

Android:layout_marginleft

Android:layout_marginright

This article is from the "bigoppoer" blog, make sure to keep this source http://bigoppoer.blog.51cto.com/9971842/1649858

Android five big layout files

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.