Four basic layouts of android--

Source: Internet
Author: User

1. Linear layout

<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"android:orientation= "Horizontal" <!--horizontal for horizontal arrangement vertical vertical arrangement--Android:layout_width= "Match_parent"Android:layout_height= "Match_parent">    <ButtonAndroid:id= "@+id/button1"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Button1" />    <ButtonAndroid:id= "@+id/button2"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Button2" />    <ButtonAndroid:id= "@+id/button3"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Button3" /></LinearLayout>

Select alignment by Layout_gravity

<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"android:orientation= "Horizontal"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent">    <ButtonAndroid:id= "@+id/button1"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:layout_gravity= "Top"Android:text= "Button1" />    <ButtonAndroid:id= "@+id/button2"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:layout_gravity= "Center_vertical"Android:text= "Button2" />    <ButtonAndroid:id= "@+id/button3"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:layout_gravity= "Bottom"Android:text= "Button3" /></LinearLayout>

As shown

Layout_width to set the scale of the screen the system adds all the controls under LinearLayout to the total value and then the layout_width of each control is the scale.

<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"android:orientation= "Horizontal"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent">    <EditTextAndroid:id= "@+id/input_message"Android:layout_width= "0DP"Android:layout_height= "Wrap_content"Android:layout_weight= "3"Android:hint= "Type Something"        />    <ButtonAndroid:id= "@+id/send"Android:layout_width= "0DP"Android:layout_height= "Wrap_content"Android:layout_weight= "2"Android:text= "Send"        /></LinearLayout>

As shown

If the button's layout_width is set to Wrap_content, EditText's layout_weight is set to 1 for the following display

2. Relative layout

  

Four basic layouts of android--

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.