Follow me on Android six layouts

Source: Internet
Author: User
Tags xml attribute

Chapter Content

1th Section Linear Layout
2nd section Relative layout
3rd Frame Layout
4th Section Table layout
5th section Grid Layout

Linear Layout

The linear layout is configured with <LinearLayout> tags, the classes in the corresponding code are android.widget.LinearLayout, and the linear layout is divided horizontally and vertically in two directions.

The common properties of linear layouts are as follows:
Android:orientation represents the layout direction, the value vertical represents the vertical layout, and the value horizontal represents the horizontal layout.
Android:gravity represents the alignment of the view
Contents include: Top, bottom, left, right, center_vertical, Center_horizontal, center, you can fill in multiple values with |
Views in layouts can use the following properties

Android:layout_gravity represents the alignment of a single view, Android:layout_weight represents the size of a single view, and when Layout_weight is 0 o'clock, the view size is determined by itself when Layout_ Weight greater than 0 o'clock, the view is stretched in linear layout direction according to specific gravity

Relative Layout

A relative layout is a layout that is set relative to the position, and the relative layout is configured using the <RelativeLayout> tag. The classes in the corresponding code are android.widget.RelativeLayout, and the views in the layout are arranged by the relative positions of each other, relative to the arrangement, relative to the alignment, and relative layout using drag-and-drop is more convenient.


The common properties available in relative layout view are as follows:
location-related properties
Android:layout_above represents above the target component
Android:layout_below is indicated below the target component
Android:layout_toleftof represents the left side of the target component
Android:layout_torightof represents the right side of the target component
Properties related to alignment
Android:alignbaseline represents the baseline alignment of the target component
Android:alignbottom is aligned with the bottom edge of the target component
Android:aligntop is aligned with the top edge of the target component
Android:alignleft is aligned to the left of the target component
Android:alignright is aligned to the right of the target component
Android:layout_centerhorizontal represents horizontal centering within a relative layout container

Android:layout_centervertical indicates vertical centering within relative layout container

Frame layout

Frame layout is a layout that stacks up views to display

Using the <FrameLayout> tag for configuration, the corresponding class is android.widget.FrameLayout, the layout of the view according to the order of writing, first added display in the bottom, and finally added to the top level, Each view can be placed in place for the layout container


Common Properties for frame layouts

Android:foreground used to represent the topmost layer of the frame layout

Android:foregroundgravity used to represent the location of the overlay content

The common properties available in the frame layout view are as follows:

Android:layout_gravity represents the location of the view, including: Top, bottom, left, right, center_vertical, Center_horizontal, center, you can fill in multiple values with |

Layout file:



<framelayout xmlns:android= "http://schemas.android.com/apk/res/android"        android:layout_width= "Match_ Parent "        android:layout_height=" match_parent ">       <textview                android:layout_gravity=" center "                Android:layout_width= "300DP"                android:layout_height= "300DP"                android:background= "#FF0000"                android: text= "@string/tip1"/>        ......</framelayout>
</pre><pre code_snippet_id= "1741515" snippet_file_name= "blog_20160702_4_51180" name= "code" class= "HTML" >
 
  

Table layout

A table layout is a layout of a row-and-column arrangement of views, configured with <TableLayout> and <TableRow> tags, and the corresponding class is android.widget.TableLayout, a pair of <tablerow The > tag contains the view displayed in a row.

Common Properties for table layouts

The android:stretchcolumns is used to specify columns that can be stretched, columns that can be stretched are stretched when the screen has white space, columns are represented by a 0-based index value, and multiple columns are separated by commas.

The android:shrinkcolumns is used to specify which columns can be compressed, and when the screen is insufficient, the columns are compressed until they are fully displayed

Android:collapsecolumns used to represent columns that can be completely collapsed

The common properties available in the table layout view are as follows:

ANDROID:LAYOUT_COLUMN Specifies the column index number, because some rows may not have a full number of columns, you need to specify the index number for the column

Grid layout

The grid layout is represented by GridLayout, which is the new layout manager for Android 4.0, which is configured with the <GridLayout> tag and the corresponding class is Android.widget.GridLayout

The common properties of the grid layout are as follows:

Android:columncount set the number of columns for this grid

Android:rowcount set the number of rows for this grid



The common properties of a submenu in a grid layout are as follows:

XML attribute description
Android:layout_column Set the sub-component in the GridLayout column
Android:layout_columnspan Sets the subassembly to span several columns in the GridLayout landscape
Android:layout_gravity Sets how this subassembly occupies the space of the grid
Android:layout_row Sets the first line of the subassembly in GridLayout
Android:layout_rowspan Sets the subassembly to span several lines vertically on GridLayout

Implementation of the view interface through grid layout



Follow me on Android six layouts

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.