Android:layout_weight detailed

Source: Internet
Author: User


Layout_weight is used to assign values to the importance of many views in a linear layout.
All views have a layout_weight value, which defaults to zero, meaning it needs to be displayed
How large a view occupies is the screen space. If you assign a value higher than zero, the parent view
The available space in the graph is split, and the split size depends on the layout_weight of each view
Value and the overall layout_weight value of the value in the current screen layout and the other view screen cloth
Percentage of the Layout_weight value of the bureau.
For example, let's say we have a text label and two text editing elements in the horizontal direction.
The text label does not specify a layout_weight value, so it will occupy the minimum space needed to provide it.
If the layout_weight value of each of the two text-editing elements is set to 1, the two are split equally
The remaining width in the parent view layout (because we declare the importance of the two equal). If two X
The text editing element where the first Layout_weight value is set to 1, and the second is set to 2,
The remaining space of two-thirds points to the first, One-third points to the second (the smaller the value, the higher the importance).
See Example:

<?XML version= "1.0" encoding= "Utf-8"?>   <LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"android:orientation= "vertical"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent"      >     <LinearLayoutandroid:orientation= "Horizontal"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent"Android:layout_weight= "1">         <TextViewAndroid:text= "Redwwwwwww"android:gravity= "Center_horizontal"Android:background= "#aa0000"Android:layout_width= "Wrap_content"Android:layout_height= "Fill_parent"Android:layout_weight= "1"/>         <TextViewAndroid:text= "Green"android:gravity= "Center_horizontal"Android:background= "#00aa00"Android:layout_width= "Wrap_content"Android:layout_height= "Fill_parent"Android:layout_weight= "2"/>         <TextViewAndroid:text= "Blue"android:gravity= "Center_horizontal"Android:background= "#0000aa"Android:layout_width= "Wrap_content"Android:layout_height= "Fill_parent"Android:layout_weight= "3"/>         <TextViewAndroid:text= "Yellow"android:gravity= "Center_horizontal"Android:background= "#aaaa00"Android:layout_width= "Wrap_content"Android:layout_height= "Fill_parent"Android:layout_weight= "4"/>     </LinearLayout>   </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.