Forty-four, Android: layout_weight

Source: Internet
Author: User

1. You can specify the filling weight for the linearlayout control. This allows its contained controls to fill the remaining space on the screen. This also avoids the congestion of all controls, but allows them to zoom in and fill in all spaces. The remaining space is allocated to the screen according to the weight ratio specified by these controls.


2. By default, the value of weight is 0, indicating that weight is displayed according to the actual size of the control. If weight is set to higher than zero.


3. The remaining space is allocated to the control based on the proportion of the Weight Value of the control to the weight of all controls. For example, there are two controls, one is 1 and the other is 2. the remaining space is allocated to control 1/(1 + 2) and control 2/(1 + 2. That is, the greater the weight, the greater the importance.


4. If linearlayout contains sub-linearlayout, the greater the weight between sub-linearlayout, the smaller the importance. If linearlayout A contains linearlayout C, D, and C with a weight of 2 and D with a weight of 1, the 2/3 space on the screen is allocated to D with a weight of 1, 1/3 distribute to C with the weight of 2. In the case of nested linearlayout, The sublinearlayout must be set with the permission value. Otherwise, the default situation is that the sublinearlayout without the permission value occupies the entire screen.

<? XML version = "1.0" encoding = "UTF-8"?> <Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" Android: Orientation = "vertical"> <linearlayout xmlns: android = "http://schemas.android.com/apk/res/android" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" Android: Orientation = "vertical" Android: layout_weight = "2"> <surfaceview Android: id = "@ + ID/surfaceview" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent"/> </linearlayout> <linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: Orientation = "horizontal" Android: layout_weight = "1" Android: layout_gravity = "center"> <button Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: Id = "@ + ID/btntakepicture" Android: gravity = "center" Android: textsize = "20px" Android: TEXT = "photo"/> </linearlayout>

 

 

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.