Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand the Android Layout XML attribute in Android UI

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail how to understand the Android Layout XML attributes in Android UI. The content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

Layout plays an important role in rapidly building the interface and improving the adaptability of the interface on different resolution screens. Here is a brief introduction to Android's Layout and a look at its implementation.

Android has Layout:FrameLayout,LinearLayout,TableLayout,RelativeLayout,AbsoluteLayout.

The XML property of the View that is laid out in Layout:

1. XML attributes common to Item in several Layout:

(1) layout_width

(2) layout_height

Note: (1) and (2) are used to determine the width and height of the View placed in the Layout: their possible values are fill_parent,wrap_content or fixed pixel values.

(3) layout_marginLeft-- > paddingLeft

(4) layout_marginTop-- > paddingTop

(5) layout_marginRight-- > paddingRight

(6) layout_marginBottom--- > paddingBottom

(supplement) layout_margin-> padding

Note: (3) (4) (5) (6) the View placed in the Layout expects it to be at a distance from the boundary of the Layout or other View.

(7) layout_gravity

Note: (7) it is used to determine the docking position of View in Layout.

FrameLayout is the simplest Layout and has only these attributes.

LinearLayout will also have:

(8) layout_weight

Note: (8) it is used to allocate the remaining space after arranging all child View in LinearLayout to each View that owns this attribute according to their layout_weight.

The line TableRow of TableLayout is a horizontal LinearLayout

RelativeLayout has 16 align-related XML attributes:

(9) the low end of the layout_alignParentBottom current control is aligned with the low end of the parent control (coincident)

(10) the left end of the layout_alignParentLeft current control is aligned with the left end of the parent control (coincident)

(11) the right end of the layout_alignParentRight current control is aligned with the right end of the parent control (coincident)

(12) the top of the layout_alignParentTop current control is aligned with the top of the parent control (coincident)

(13) the current layout_centerHorizontal control is located in the middle horizontal position of the parent control (the middle in the horizontal direction)

(14) the layout_centerInParent current control is located in the middle of the vertical and horizontal direction of the parent control (in the middle of the vertical direction)

(15) the current layout_centerVertical control is located in the middle of the vertical direction of the parent control (in the middle of the plane)

(16) layout_above places the current control above the given id control

(17) layout_below places the current control below the given id control

(18) layout_toLeftOf places the current control on the left side of the given id control

(19) layout_toRightOf places the current control on the right side of the given id control

(20) layout_alignBottom coincident the current control with the bottom of the given id control (note that the id control is available and given to align)

(21) layout_alignLeft coincident the current control with the left side of the given id control

(22) layout_alignRight coincident the current control with the right side of the given id control

(23) layout_alignTop coincident the current control with the top of the given id control

(24) layout_alignBaseline coincident the BaseLine of the current control with the BaseLine that gives the id control t, which is mainly used for Label or other widgets that contains text.

Note: (9) to (24) are used to determine the position of View in RelativeLayout relative to Layout or other View in Layout.

According to the Android documentation, Android traverses the tree composed of Layou and View twice, once a measure call to determine the size of the Layout or View, and a layout call to determine the location of the Layout or view. Of course, my own copycat implementation merged these two calls together. That is, Layout measure itself once before arranging, and then call the Layout method recursively on the View. The size of this must be determined. Then use the determined size to position it with the gravity or align attribute, and use margin to adjust the position.

Add:

The difference between 1.android:paddingLeft and android:layout_marginLeft:

Padding margin is the meaning of margin, the key question is to understand what is relative to what margin.

Padding is the margin of the content of a control relative to the edge of the control.

Layout_margin is the margin of the control's edge relative to the parent space.

The difference between 2.android gravity and layout_gravity

The android:gravity attribute is the qualification of the view content. For example, a text on a button. You can set the text to the left and right of the view. This property does this.

Android:layout_gravity is used to set the position of the view relative to the parent view. For example, if a button is in linearlayout, you can set it through this property if you want to place the button on the left, right, etc.

This explains why we have an outermost layout, and then there are several layouts in it. If we want to make these layouts at the bottom, we can set androi:gravity= "botton" in the outermost layout properties because gravity works on the contents inside.

On how to understand the Android Layout XML attribute in Android UI to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report