Android Linear layout LinearLayout (vii)

Source: Internet
Author: User

First, understand a few properties:

1. Layout

1) android:orientation= "vertical" vertical layout

2) android:orientation= "Horizontal" horizontal layout


2. High and wide layout of control content

1) android:layout_width= "Match_parent", covered with the entire screen. [Match parent window]

2) android:layout_height= "Wrap_content", layout elements will change size based on content. [Content includes]


3. Layout scale

All views have a layout_weight value, which defaults to zero, meaning how much screen space you need to show how large the view will occupy. If you assign a value above zero, the free space in the parent view is split, and the split size depends on the layout_weight value of each view and the overall layout_weight value of the value in the current screen layout and the layout_ of the other view screen layout The percentage of the weight value.


Second, the following two examples of implementation:

1) three buttons horizontally placed


<linearlayout android:layout_width= "match_parent" android:layout_height= "Wrap_content" Android:ori entation= "Horizontal" > <button android:layout_width= "match_parent" Android:layout_heig ht= "Wrap_content" android:layout_weight= "1" android:text= "MC"/> <button and            Roid: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>
Borrow Layout_weight to make the three buttons occupy the same proportion of the display.
Second, two-level button: The first layer three, the second 2


<linearlayout android:layout_width= "match_parent" android:layout_height= "Wrap_content" Android:ori entation= "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:l                Ayout_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>
Use a large layer first, set the weight scale is 3. The weight of the first button in the second layer is 2/3 of that of the layer.

Android Linear layout LinearLayout (vii)

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.