Android linear Layout (LinearLayout) related official documents-Guide Section

Source: Internet
Author: User
Tags creative commons attribution

Android linear Layout (LinearLayout) related official documents-Guide Section

The beautiful Life of the Sun Vulcan (http://blog.csdn.net/opengl_es)

This article follows "Attribution-non-commercial use-consistent" authoring public agreement

Reprint Please keep this sentence: Sun Vulcan's Beautiful Life-this blog focuses on Agile development and mobile and IoT device research: IOS, Android, HTML5, Arduino, Pcduino , or else. Articles from this blog refuse to be reproduced or reproduced. Thank you for your cooperation.



Android Official document Linear layout related Resources link Summary For example the following:

Android-sdk-macosx-4.4.2/docs/guide/topics/ui/layout/linear.html

Android-sdk-macosx-4.4.2/docs/reference/android/widget/linearlayout.html

Android-sdk-macosx-4.4.2/docs/reference/android/widget/linearlayout.layoutparams.html



Given the difficulty of visiting online documents, here is the relative path to the local document.



Summary of Highlights:

1, does not specify the weight of the sub-view, whether it occupies space, the space occupied by what the specific decision. Do you press content, or do you press the set width, high value, or the Onmeasure method of Android.view.View overloaded by a child view?

A, theoretical analysis results: from the original sentence "The other" wouldexpand equally to fill the space remaining after all three fields is measured. ", it is possible to determine the occupied space according to the onmeasure measured width and height. and needles for most components. This method is overloaded to determine the space occupied by the content, i.e. the width and height of this component is set to the space occupied by "Wrap_content".

b, the actual test results to be supplemented.

2, why the text hint, the width and height of the property to be set to "0DP"? The assumption is not set to "0DP". Does its value affect the amount of unauthorized space that the child view itself occupies? Assume that the space allocated by weight does not have a wide or high value set. What would happen? Assuming that the width or height is set to "0DP", the space allocated by the weights still does not have its own content taking up much space. What would happen?

A, theoretical analysis results: no train of thought. Do not know what will be the result;

b, the actual test results to be supplemented.


Source: guide/topics/ui/layout/linear.htmlLinear layouts Linear layoutcontent in this document
In this DOCUMENT
    1. Layout weights
      Layout Weight
    2. Demo Sample
      Example
Key classes
KEY CLASSES
    1. 线性布局 
      LinearLayout
    2. 线性布局.布局參数
      LinearLayout.LayoutParams

< Span style= "COLOR: #006600" > linear layout is a grouping of views. It aligns all the sub-views in a single direction, either vertically or horizontally. Able to use the android:orientation &NBSP;   property to specify the layout direction.


LinearLayout
is a view group this aligns all children in a single direction, vertically or horizontally. You can specify the layout direction with the android:orientation attribute.

All sub-views of a linear layout are stacked on a one-by-one basis. So a vertical list has only one sub-view per row, no matter how wide; the horizontal list is only a row high (the height of the highest child view, plus an inner fill).

The linear layout adheres to the margins between the child views and the gravity of each child view (right, center, or left).
All children of a LinearLayout is stacked one after the other, so a vertical list would only has one child per row, no matter ho W wide they is, and a horizontal list would only is one row high (the height of the tallest child, plus padding). A LinearLayout respects margins between children and the gravity (right, center, or left alignment) of each CHI Ld.

Layout weights
Layout Weight Equal weighted sub-view
Equally weighted children

To create a line layout, go inside it. Make each child view use the same amount of screen space. Then set each diagram'sandroid:layout_height 属性为 "0dp"(针对于竖向布局)或者 android:layout_width 属性为 "0dp"(针对于水平布局)。然后,为每个视图设置 android:layout_weight 属性值为 "1"。
to Create a linear layout in which each child uses the same amount of space on the screen, SE T the android:layout_height  of each view to   "0DP"   (for a vertical layout) or the < Code style= "font-size:undefined; line-height:14px ">android:layout_width  of each view to " 0DP "   (for a horizontal layout). Then set The android:layout_weight  of each View To  "1" .

< Span style= "COLOR: #006600" > Linear layout is also supported by the properties &NBSP; android:layout_weight   assigns a weight value to each child view.

linearlayout  also supports assigning a  weight  to individual children with The android:layout_weight  attribute. This attribute assigns an "importance" value to a view in terms of what much space is should occupy on the screen. A larger weight value allows it to expand to fill any remaining space in the parent view. Child views can specify a weight value, and then any remaining space in the view group are assigned to children in the prop Ortion of their declared weight. Default weight is zero.

for example. Let's say there are three of texts. And two of the 1 weights are declared, and there is one without a given weight, then the third text field without weights will not grow and will only occupy the required area of its content ( pending test If you specify a width or height without assigning a weight, what is the required area of the content to refer to the actual content or the width and height values? Or is it necessary to get the content of the view through the Onmeasured method? )。 The other two domains will be equally populated with the remaining space measured in all three domains. Suppose that the third field is then given a weight of 2 (instead of 0). Then it now declares that it weighs more than the other two weights. So it gets half of the total remaining space, and the first two halves of the rest.
for example, if there is three text fields and both of them declare a weight of 1, While the other is given no weight, the third text field without weight would not grow and would only be occupy the area Requi Red by its content. The other and the expand equally to fill the space remaining after any three fields is measured. If The third field is then given a weight of 2 (instead of 0), then it's now declared more important than both the others , so it gets half the total remaining space and while the first and the share the rest equally.

Sample Example
Example
<?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:paddingleft="16DP"    Android:paddingright="16DP"    android:orientation="Vertical" >    <edittext        Android:layout_width="Fill_parent"        Android:layout_height="Wrap_content"        Android:hint="@string/to" />    <edittext        Android:layout_width="Fill_parent"        Android:layout_height="Wrap_content"        Android:hint="@string/subject" />    <edittext        Android:layout_width="Fill_parent"        Android:layout_height="0DP"        Android:layout_weight="1"        android:gravity="Top"        Android:hint="@string/message" />    <button        Android:layout_width="100DP"        Android:layout_height="Wrap_content"        android:layout_gravity="Right"        Android:text="@string/send" /></LinearLayout>

For a detailed description of the properties available for each sub-view of the linear layout, you can viewLinearLayout.LayoutParams 。
For details on the attributes available to each child view of a LinearLayout , see LinearLayout.LayoutParams .

Except as noted, this content is licensed under Creative Commons Attribution 2.5. For details and restrictions, see Thecontent License.

About Android |  Legal | Support








Android linear Layout (LinearLayout) related official documents-Guide Section

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.