Android:gravity and Android:layout_gravity

Source: Internet
Author: User

LinearLayout has two very similar properties: Android:gravity and Android:layout_gravity. The difference is that android:gravity is used to set the alignment of the view component, and android:layout_gravity is used to set the alignment of the container component.

Popular point is that:

The Android:gravity property is the qualification for the view content. For example, a button above the text. You can set the text on the left side of the view, on the right, and so on. This property is done with this.
Android:layout_gravity is used to set the position of the view relative to the parent view. For example, a button in the LinearLayout, you want to put the button on the left to the right and so on can be set by this property.
We get the most out of the layout, and then we have a few layouts, and if you want to make these layouts bottom, you can set the androi:gravity= "Botton" in the properties of the most out-of-layout, because gravity is working on the contents.

Which layouts are supported? Application restrictions?

When the LinearLayout property of the parent layout is androidrientation= "vertical", android:layout_gravity= "? "This will only take effect when the landscape is set to horizontal. such as: Left,right,center_horizontal, etc.

When the LinearLayout property of the parent layout is androidrientation= "Horizental", android:layout_gravity= "? "This is set to portrait when it takes effect. such as: Top,bottom,center_vertical and so on;

One of the more special is the center, whether it is horizontal or vertical, it always has a direction to work

Lianjie:http://www.cnblogs.com/xiaoran1129/archive/2013/03/26/2982733.html

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.