Android Basic UI article------six basic layouts

Source: Internet
Author: User

1. Linear Layout LinearLayout
Common Properties:
Android:gravity to set the alignment of child controls
Android:orientation arrangement (divided into horizontal and vertical arrangement)
Android:layout_gravity Setting the alignment relative to the parent control
Android:layout_weight the weight of the child control in the layout

! LinearLayout does not wrap, so if the child controls are outside the screen range, they will not be displayed.

2. Table Layout Tablelayout
Inherited from LinearLayout, so its essence is still linear layout.
Instead of explicitly declaring how many rows and columns it contains, the table layout controls rows and columns by adding TableRow and other components.
Sets a tablerow that is equivalent to adding a table row. Adding a child control in it is equivalent to adding a column.

Three ways of behaving:
Android:collapsecolumns need to be hidden column ordinal
Android:shrinkcolumns column ordinal of a column allowed to be shrunk
Android:strechcolumns column ordinal of the column that is allowed to be stretched

3. Frame Layout Framelayout
Creates a blank area for each component that is added to it, and the first created component is placed on the bottom (similar to the stack structure)

Property:
You can use layout_gravity to set the alignment relative to the parent layout '

Example: Neon effect

4. Relative Layout relativelayout
Gravity alignment of sub-assemblies
Centerhorizontal Horizontal Center
Centervertical Vertical Center
Centerinparent in middle position of parent container
Alignparentbottom is aligned to the bottom of the layout container
Alignparentleft is aligned to the left of the layout container
Alignparentright is aligned to the right end of the layout container
Alignparenttop is aligned to the top of the layout container
Torightof at the right end of the specified ID component
Toleftof at the left end of the specified ID component
Above located above the specified ID component
Below located below the specified ID component
AlignTop aligns with the top bounds of the specified ID component
AlignBottom aligns with the bottom boundary of the specified ID component
AlignLeft aligns to the left edge of the specified ID component
AlignRight aligns to the right edge of the specified ID component

5. Grid Layout GridLayout
The new layout after Android4.0.

Property:
Alignmentmode Alignment Mode
ColumnCount Number of columns
RowCount Number of rows

The properties of the child component
Layout_column sets the sub-component in the first column
Layout_columnspan sets the sub-component across several columns horizontally
Layout_row set the subassembly in the first few lines
Layout_rowspan set the subassembly lengthwise across several lines
Layout_gravity to set the alignment of sub-components

The code dynamically sets the rows and columns:
1. Set the row where the new component is located
Gridlayout.spec Rowspec = gridlayout.spec (int);
2. Set the column where the new component is located
Gridlayout.spec Columnspec = gridlayout.spec (int);
3. Loading rows and columns into GridLayout
Gridlayout.layoutparams params = new Gridlayout.layoutparams (ROWSPEC,COLUMNSPEC);
4. Specify that the component fills the parent container
Params.setgravity (Gravity,fill);
5. Load the component into the layout
Gridlayout.addview (View,params);

Example: Calculator UI layout

6. Absolute layout absolutelayout
The resolution of the phone screen varies widely, and it is difficult to use absolute layout to accommodate different screen sizes. So, Absolutelayout is obsolete.

Copyright notice: Just out of the original content of the pot, I hope you have help ~

Android Basic UI article------six basic 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.