Android ApiDemos example resolution (143): Views-& gt; Layouts-& gt; Line

Source: Internet
Author: User

In LinearLayout, you can set weight for a sub-View. horizontal or vertical sub-views cannot overlay the entire screen. The remaining space is occupied by those views with weights. The default View weight is 0 (layout_weight = 0 ).

Using a basic wEight algorithm, the remaining space of LinearLayout has a View with "weight" allocated proportionally based on its weight.

In this example, the three sub-views of LinearLayout only have the weight android: layout_weight = "1" set for the second TextView. Therefore, this View occupies the entire middle part and the third TextView is squeezed to the bottom. If android: layout_weight = "1" is added to the other two textviews, the three textviews are evenly distributed on the screen:

<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: orientation = "vertical"
Android: background = "@ drawable/blue"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent">

<! -View1 goes on top->
<TextView
Android: background = "@ drawable/box"
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content"
Android: text = "@ string/linear_layout_3_top"/>

<! -View2 goes in the middle->
<TextView
Android: background = "@ drawable/box"
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content"
Android: layout_weight = "1 ″
Android: text = "@ string/linear_layout_3_middle"/>

<! -View3 goes on the bottom->
<TextView
Android: background = "@ drawable/box"
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content"
Android: text = "@ string/linear_layout_3_bottom"/>

</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.