Problems with Android layout_gravity failure

Source: Internet
Author: User

It is believed that for Android beginners, everyone has been confused by the two extremely similar attributes in layout.
Simply use the search tool and we won't find the answer to the following:

Layout_gravity represents the position of the component itself in the parent component gravity represents the position of the subassembly in the component             

It seems simple.

Why this simple truth, there are always classmates will find, at "some time", layout_gravity this attribute is not good, lost its due role

Where exactly is the problem?

When the LinearLayout property of the parent layout is android:orientation= "vertical", android:layout_gravity= "? " This will only take effect when the landscape is set to horizontal. such as: Left,right,center_horizontal and so on;
When the LinearLayout property of the parent layout is android:orientation= "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 , because linearlayout he can only have a direction,

This nm, does make a person egg ache. In fact, there is a bit of truth, that is, linearlayout horizontal, if there are many children, then do not know who put the most right,

There are two ways to fix it,

(1) Use Relativelayout Bar, this is crap bar, haha

(2) in LinearLayout set android:gravity this from the official API explanation is how to place its content, linearlayout content is not his children, problem solving

Problems with Android layout_gravity failure

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.