Android Layout Properties

Source: Internet
Author: User

The introduction of Android application development engineers will inevitably encounter UI designers, and need to quickly implement UI effects in the short term. This requires Android application development engineers to have a familiar understanding of the Android layout layouts, in order to quickly build up the UI framework.
The main layout of Android layoutandroid is: Framelayout, LinearLayout, Relativelayout, Tablelayout, Absolutelayout
Common XML properties each control in Android occupies a rectangular area that handles interactive events related to a rectangular region and draws the interactive interface of the control object within that area. In Android, the length-to-width description of the rectangular area of a control object is mainly through the following two XML attributes:
1. Layout_width2. Layout_height
Their values may be fixed pixel values, or they may have values of match_parent, wrap_content.
The view placed in layout is designed to be a distance away from the layout boundary or other view, thus providing the following XML attributes:
3. Layout_marginleft----PADDINGLEFT4. Layout_marginright----PADDINGRIGHT5. Layout_margintop----PADDINGTOP6. Layout_marginbottom----PADDINGBUTTOM7. Layout_margin----Padding
Margin is used to set the distance between the child control of a container control object and its rectangular area, while padding is used to indicate the distance between the contents of the control object and the edge of the space rectangle. I use a picture to describe the difference between margin and padding, as follows:

There is also an XML attribute to determine the view's docking position in layout:
8. layout_gravity
The special XML attribute framelayout is the simplest layout, so it has only the public properties above.
Linearlayoutlineartlayout also has an XML attribute for allocating the remaining space after all sub-view arrangements are allocated according to their configuration scale
9. Layout_weight
The Tablelayout line TableRow is a horizontal (horizontal) LinearLayout
Relativelayoutrelativelayout should be the most common and best use of the parent control, relative position can make our UI better adaptive to a variety of different resolutions of the screen. There are 16 XML attributes in Relativelayout that are related to align:
Layout_alignparentbottom----The bottom of the current control is coincident (aligned) with the base of the parent control 11. Layout_alignparenttop----The top of the current control is coincident (aligned) with the top of the parent control 12. Layout_alignparentleft----The left side of the current control is coincident (aligned) to the right of the parent control 13. LAYOUT_ALIGNPARENTRGIHT----The right side of the current control is coincident (aligned) to the right side of the parent control

Layout_centerhorizontal----The current control is in the horizontal middle position of the parent control (in the middle of the horizontal direction) 15. Layout_centervertical----The current control is in the vertical middle position of the parent control (in the middle of the vertical direction) 16. Layout_centerinparent----The current control is in the middle of the parent control (both horizontal and vertical)
Layout_above----Make the current control above 18 of the specified ID control. Layout_below----Causes the current control to be located below the specified ID control
Layout_toleftof----Make the current control on the left side of the specified ID control
Layout_torightof----Make the current control on the right side of the specified ID control

Layout_alignbottm----Make the current control coincident (aligned) with the bottom of the specified ID control 22. Layout_aligntop----to coincide (align) the current control with the top of the specified ID control
Layout_alignleft----Make the current control coincident (aligned) to the left of the specified ID control
Layout_alignright----Make the current control coincident (aligned) to the right of the specified ID control 25. Layout_alignbaseline----The baseline of the current control coincides with the baseline of the given ID control
Explain,BaseLineEquivalent to the line below the writing text in the notebook, such as below.
XML layout file:
<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android"    xmlns:tools= "http// Schemas.android.com/tools "    android:layout_width=" match_parent "    android:layout_height=" Match_parent " >    <textview        android:id= "@+id/text1"        android:layout_width= "wrap_content"        android:layout_ height= "Wrap_content"        android:background= "#aa0000"        android:text= "HELLO"/>    <textview        Android:id= "@+id/text2"        android:layout_width= "wrap_content"        android:layout_height= "Wrap_content"        android:layout_torightof= "@id/text1"        android:background= "#00ff00"        android:padding= "20DP         " android:text= "World"/></relativelayout>
:
After adding android:layout_alginbaseline= "@id/test1":


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.