Android Layout LinearLayout

Source: Internet
Author: User

LinearLayout

1. Core attributes

Height: layout_height (based on content wrap_content; parent control;)

Width: layout_width

Direction: orientation (longitudinal vertical; transverse horizontal;)

Location: layout_gravity (center center; right;)

2. Equal control

Layout_width set to 0DP layout_weight to weight ratio is recommended by Google

<?XML version= "1.0" encoding= "Utf-8"?><LinearLayoutandroid:orientation= "vertical"xmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_height= "Wrap_content"Android:layout_width= "Match_parent">    <!--horizontal layout_width= "Match_parent" determines its width based on the width of the parent control -    <LinearLayoutandroid:orientation= "Horizontal"xmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_height= "Wrap_content"Android:layout_width= "Match_parent">        <!--Layout_width set to 0DP layout_weight to weight ratio is recommended by Google -        <ButtonAndroid:layout_width= "0DP"Android:layout_height= "Wrap_content"Android:layout_weight= "1"Android:background= "#234578"Android:text= "equal to 1"/>        <ButtonAndroid:layout_width= "0DP"Android:layout_height= "Wrap_content"Android:layout_weight= "1"Android:background= "#234578"Android:text= "equal to 1"/>        <ButtonAndroid:layout_width= "0DP"Android:layout_height= "Wrap_content"Android:layout_weight= "2"Android:background= "#284578"Android:text= "equal (+)"/>    </LinearLayout>    <!--Horizontal non-uniform layout_width= "wrap_content" determines its width depending on the width of the content -    <LinearLayoutandroid:orientation= "Horizontal"xmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_height= "Wrap_content"Android:layout_width= "Wrap_content"Android:layout_margintop= "10DP">        <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:background= "#897654"Android:text= "Non-equal 1"/>        <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:background= "#897654"Android:text= "===== non-uniform 123====="/>        <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:textallcaps= "false"Android:background= "#897654"Android:text= "Demo"/>    </LinearLayout>    <!--Horizontal Dividing -    <LinearLayoutandroid:orientation= "Horizontal"xmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_height= "Match_parent"Android:layout_width= "Wrap_content"Android:layout_margintop= "10DP">        <!--Vertical Dividing -        <LinearLayoutandroid:orientation= "vertical"xmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_height= "Match_parent"Android:layout_width= "0DP"Android:layout_weight= "1">            <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "0DP"Android:layout_weight= "2"Android:background= "#457421"Android:text= "equal to 1"/>            <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "0DP"Android:layout_weight= "1"Android:background= "#126735"Android:text= "equal to 2"/>            <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "0DP"Android:layout_weight= "1"Android:background= "#843975"Android:text= "equal to 3"/>        </LinearLayout>        <!--vertical row values determine height -        <LinearLayoutandroid:orientation= "vertical"xmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_height= "Wrap_content"Android:layout_width= "0DP"Android:layout_weight= "1"Android:layout_marginleft= "20DP">            <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "44DP"Android:background= "#547836"Android:text= "Button 1"/>            <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "66DP"Android:background= "#837282"Android:text= "button 2"/>            <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "98DP"Android:layout_weight= "2"Android:background= "#973422"Android:text= "button 3"/>        </LinearLayout>    </LinearLayout>    <LinearLayoutandroid:orientation= "vertical"xmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_height= "Wrap_content"Android:layout_width= "Wrap_content"android:layout_gravity= "Right">        <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "44DP"Android:background= "#547836"Android:text= "On the right"/>    </LinearLayout>    <LinearLayoutandroid:orientation= "vertical"xmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_height= "Wrap_content"Android:layout_width= "Wrap_content"android:layout_gravity= "Center">        <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "44DP"Android:background= "#547836"Android:text= "Centered"/>    </LinearLayout></LinearLayout>

  

Android Layout LinearLayout

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.