Android linear layout LinearLayout (7) and linearlayout

Source: Internet
Author: User

Android linear layout LinearLayout (7) and linearlayout

I. First, I want to know several attributes:

1. Layout

1) android: orientation = "vertical" vertical layout

2) android: orientation = "horizontal" horizontal layout


2. control content height and width Layout

1) android: layout_width = "match_parent", full of the screen. [Match parent window]

2) for android: layout_height = "wrap_content", the layout element will be changed based on the content. [The content includes]


3. layout Ratio

All views have a layout_weight value. The default value is zero, which means that the size of the view to be displayed occupies the size of the blank screen. If a value higher than zero is assigned, the free space in the parent view is split, the split size depends on the layout_weight value of each view and the ratio of the layout_weight value in the current screen layout to the layout_weight value in the screen layout of other views.


2. The following two examples are implemented:

1) Place the three buttons horizontally


  <LinearLayout        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:orientation="horizontal" >        <Button            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_weight="1"            android:text="mc" />        <Button            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_weight="1"            android:text="m+" />        <Button            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_weight="1"            android:text="m-" />        <Button            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_weight="1"            android:text="mr" />    </LinearLayout>
Use layout_weight to make the three buttons occupy the same proportion.
2. Two buttons: three buttons at the first layer and two buttons at the second layer


<LinearLayout        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:orientation="vertical" >                <LinearLayout            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_weight="3"            android:orientation="horizontal" >            <Button                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:layout_weight="1"                android:text="1" />            <Button                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:layout_weight="1"                android:text="2" />            <Button                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:layout_weight="1"                android:text="3" />        </LinearLayout>                   <LinearLayout            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_weight="3"            android:orientation="horizontal" >                              <Button                android:layout_width="0px"                android:layout_height="wrap_content"                android:layout_weight="2"                android:text="0" />            <Button                android:layout_width="0px"                android:layout_height="wrap_content"                android:layout_weight="1"                android:text="." />             </LinearLayout>    </LinearLayout>
First use a large layer and set the weight ratio to 3. The weight of the first button on the second layer accounts for 2/3 of the layer.

Related Article

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.