Android Common layout class finishing (i)

Source: Internet
Author: User

Android Common layout class finishing

Recently back to do a bit of Android project, found that more and more not from the heart, a lot of things are forgotten, simple page layout is also a lot of writing, first or first of all to sort out some confusing concepts first

Layout_width/layout_height in two different ways

①wrap_content can wrap the contents of the

②fill_parent/match_parent fills the space of the parent view

LinearLayout

Aligns each sub-view by vertical (vertical) or horizontal (horizontal), which contains child controls that are arranged horizontally or vertically, the vertical layout is the structure of n-row columns, the horizontal layout is a single row n-column structure, and allows a weight property to be set for each child view To control the relative size within the available space

android:layout_weight= "1"

The control's Layout_weight property is set to control the relative size of the individual controls in the layout, describing the proportion of the elements that the element occupies in the remaining space.

A linear layout assigns a occupied area to the control based on the ratio of the layout_weight value of the control to the sum of the layout_weight value of all controls in its layout.

Example: There are two buttons in the horizontal layout of the LinearLayout, and the Layout_weight property value of the two button is 1, then both of them will be stretched to half the width of the screen. If layout_weight refers to 0, the control is displayed at its original size, is not stretched (by default, 0), and for the remaining Layout_weight property values greater than 0, the system subtracts the width or height of the control with the Layout_weight property value of 0. Then use the remaining width or height to assign the width or height of each control to the corresponding proportions.

① Three button weight are not set, default is 0, each button occupies its own space


② Three button weight are set to 1 android:layout_weight= "1", each button consumes 1/3

③ three button weight respectively set to 0,1,2,test occupy their original size, test2 occupy the remaining space of 1/3,test3 occupy the remaining space of 2/3

android:gravity The difference from Android:layout_gravity

Android:layout_gravity refers to the alignment of the element relative to its parent element. For example, a button in the LinearLayout, you want to put the button in the LinearLayout left, on the right and so on can be set by this property.

Android:gravity refers to the alignment of the child elements of this element relative to it. property is the qualification of the content in the view. For example, a button above the text. You can set the text relative to the view's left, right, and so on. Android:gravity= "Top" (buttom, left, right, center_vertical, fill_vertical, Center_horizontal, Fill_horizontal, center , fill, clip_vertical, clip_horizontal) controls the alignment of controls in the layout. If a control that does not have a child control sets this property, it indicates the alignment of its contents, such as the alignment of the text inside the TextView, and if the control with the child control sets this property, it indicates the alignment of its child controls, and if multiple property values need to be set, use the | To combine

Relativelayout

Define the relative position between each sub-view and other views and screen boundaries

First Class: Property value is True or False

Android:layout_centervertical

Center vertically

Android:layout_centerinparent

Fully centered relative to parent element

Android:layout_alignparentbottom

Snaps to the bottom edge of the parent element

Android:layout_alignparentleft

Snaps to the left edge of the parent element

Android:layout_alignparentright

Snaps to the right edge of the parent element

Android:layout_alignparenttop

Snaps to the top edge of the parent element

Android:layout_alignwithparentifmissing

If you can't find a sibling, use the parent element as a reference.

Second class: The attribute value must be the reference name of the id "@id/id-name"

Android:layout_below

At the bottom of an element

Android:layout_above

At the top of an element

Android:layout_toleftof

On the left side of an element

Android:layout_torightof

On the right side of an element

Android:layout_aligntop

Aligns the top edge of this element with the top edge of an element

Android:layout_alignleft

Aligns the left edge of this element with the left edge of an element

Android:layout_alignbottom

Aligns the bottom edge of this element with the bottom edge of an element

Android:layout_alignright

Aligns the right edge of this element with the right edge of an element

Class III: Attribute values are specific pixel values, such as 30dip, 40px

Android:layout_marginbottom

The distance from the bottom edge of an element

Android:layout_marginleft

The distance from the left edge of an element

Android:layout_marginright

Distance from the right edge of an element

Android:layout_margintop

The distance from the top edge of an element


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.