The layout of Android development

Source: Internet
Author: User

There are more layouts with linear layouts, relative layouts, and frame layouts.

Linear layout

Features: The components are arranged in a single arrangement, and can be arranged horizontally or vertically by setting them.

Frame layout

Features: One component frame, superimposed, starting position in the upper left corner of the layout, can be set to control the position of the component.

As the following XML file, defined 6 TextView, each textview is set in the middle of the layout, each color is different, and the more in the outer layer, the smaller the area, the following effect is formed. Note that in a frame layout, a control that is declared in the upper layer, if a control is declared before the B control, is overwritten by the B control.

<?XML version= "1.0" encoding= "Utf-8"?><Framelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent"    ><!--Define 6 TextView, then define the TextView at the bottom and define the TextView on the upper level. -<TextViewAndroid:id= "@+id/view01"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:layout_gravity= "Center"Android:width= "320px"Android:height= "320px"Android:background= "#f00"    /><TextViewAndroid:id= "@+id/view02"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:layout_gravity= "Center"Android:width= "280px"Android:height= "280px"Android:background= "#0f0"    /><TextViewAndroid:id= "@+id/view03"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:layout_gravity= "Center"Android:width= "240px"Android:height= "240px"Android:background= "#00f"    /><TextViewAndroid:id= "@+id/view04"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:layout_gravity= "Center"Android:width= "200px"Android:height= "200px"Android:background= "#ff0"    /><TextViewAndroid:id= "@+id/view05"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:layout_gravity= "Center"Android:width= "160px"Android:height= "160px"Android:background= "#f0f"    /><TextViewAndroid:id= "@+id/view06"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:layout_gravity= "Center"Android:width= "120px"Android:height= "120px"Android:background= "#0ff"    /></Framelayout>

Effect:

Figure 1

Relative layout

Features: component location can be determined by relative sibling components, parent containers.

As shown in the following code, its effect is 2, the first TextView by android:layout_centerinparent= "true" so that it is in the middle of the layout, The next 4 TextView, by describing their position relative to the first TextView position, form the effect of Figure 2.

<?XML version= "1.0" encoding= "Utf-8"?><Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"android:orientation= "vertical"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent"    ><!--defines the component in the middle of the parent container -    <TextViewAndroid:id= "@+id/view01"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:background= "@drawable/leaf"android:layout_centerinparent= "true"    /><!--defines that the component is located above the view01 component -<TextViewAndroid:id= "@+id/view02"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:background= "@drawable/leaf"Android:layout_above= "@id/view01"Android:layout_alignleft= "@id/view01"    /><!--defines that the component is located below the View01 component -<TextViewAndroid:id= "@+id/view03"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:background= "@drawable/leaf"Android:layout_below= "@id/view01"Android:layout_alignleft= "@id/view01"    /><!--defines that the component is on the left side of the view01 component -<TextViewAndroid:id= "@+id/view04"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:background= "@drawable/leaf"Android:layout_toleftof= "@id/view01"Android:layout_aligntop= "@id/view01"    /><!--defines that the component is located on the right side of the VIEW01 component -<TextViewAndroid:id= "@+id/view05"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:background= "@drawable/leaf"Android:layout_torightof= "@id/view01"Android:layout_aligntop= "@id/view01"    />        </Relativelayout>

Figure 2

The layout of Android development

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.