Getting started with Android: Layout

Source: Internet
Author: User

Absolutelayout is not introduced because it has been abolished;
As long as there is an interface, there will be a layout, like swing. Although one is a desktop application and the other is a mobile application, they are similar.

1. linearlayout


Default layout. Components are arranged in a very orderly manner in the predefined direction, similar to flowlayout in swing;
Note:

 
 
 
 
 
 
 
(1) You can add Android: orientation: vertical/horizontal in <linearlayout>. (2) You can nest <linearlayout>; 

2. framelayout


Each component is in the upper left corner. If multiple components appear together, they overlap, similar to the animations superimposed by git;
Application: Online Video Player

Click the button to start playing the video;Main. xml

<? XML version = "1.0" encoding = "UTF-8"?> <Framelayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" Android: Orientation = "vertical"> <imageview Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" Android: src = "@ drawable/frame3"/> <imageview Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: src = "@ drawable/frame2" Android: layout_gravity = "center" // center/> </framelayout>
3. relativelayout


Positioning of each component is based on the up and down, left and right of other components. The default positioning is the top left;
(1) Positioning and componentsAndroid: layout_below = "@ ID/.." Android: layout_above = "@ ID/" Android: layout_toleftof = "@ ID/" Android: layout_torightof = "@ ID /"(2) Positioning and component edge alignmentAndroid: layout_alignleft = "@ ID/" Android: layout_alignright = "@ ID/" Android: layout_aligntop = "@ ID/" Android: layout_alignbottom = "@ ID /"(3) Align positioning with the edge of the parent componentAndroid: layout_alignparenttop = "true" Android: layout_alignparentbottom = "true" Android: layout_alignparentleft = "true" Android: layout_alignparentright = "true"(4) relationships with the entire ScreenAndroid: layout_centerhorizontal = "true" Android: layout_centervertical = "true" Android: layout_centerinparent = "true"(5) distance between componentsAndroid: layout_margintop = "5dp" Android: layout_marginleft = "5dp" Android: layout_marginright = "5dp" Android: layout_marginbottom = "5dp" Android: layout_margin = "5dp"

4. tablelayout


Similar to gridlayout in swing;
Each row in the table layout is enclosed by <tabrow>. The following attributes can be defined in <tablelayout>:
(1) Android: shrinkcolumns = "1" indicates that if there is too much content in the 2nd controls, it will contract and expand to the second line, instead of extending. (2) Android: stretchcolumns = "2" if there is blank, 3rd controls are filled;
In the control, set: (1) Android: layout_column = "2" to place the control in 3rd positions; (2) Android: layout_span = "2" to occupy 2 Unit positions;

TIPS: simple layout tool droiddrawhttp: // code.google.com/p/droiddraw/downloads/detail? Name1_droiddraw-r1b22.zip & can = 2 & Q =



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.