Android:layout_gravity and Android:gravity

Source: Internet
Author: User

In wirelessly these two properties are often used, specifically to summarize:

Android:layout_gravity:XML inside the hint is this, standard gravity constant, the child supplies to its parent. [flag], I roughly translate a constant that a child view provides to the parent view as the specified location.

Android:gravity:Specifies How to align the text by the view's x-and/or y-axis when the text is smaller than the view. [flag], the text is a bit long, roughly meaning that this property is a property that determines how to determine the content of the view

Android:layout_gravity can only be used with LinearLayout, in LinearLayout, specifies that the layout is valid, that is, when the property is developed for a control or layout, the parent layout must be linearlayout to be specified, otherwise there is no , there is no hint in XML, in particular, when linearlayout specifies android:orientation= "vertical", android:layout_gravity is only valid in horizontal direction; when Android:o When rientation= "Horizontal", the property is only valid in the vertical direction.

Note that if the child view is not centered, it may be because the Layout_width or Layout_height property is Fill_parent, and changed to Wrap_content

1 linearlayout nested relativelayout: valid, which in turn invalidates the property.2 <LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"3 Android:layout_width= "Fill_parent"4 Android:layout_height= "Fill_parent"5 android:orientation= "vertical" >6 7     <Button8         Android:layout_width= "Wrap_content"9 Android:layout_height= "Wrap_content"Ten Android:text= "AAA" /> One  A     <Button -         Android:layout_width= "Wrap_content" - Android:layout_height= "Wrap_content" the Android:text= "AAA" /> -  -     <Button -         Android:layout_width= "Wrap_content" + Android:layout_height= "Wrap_content" - Android:text= "AAA" /> +  A     <Relativelayout at         android:gravity= "Center" - Android:layout_width= "Fill_parent" - Android:layout_height= "Fill_parent" - android:layout_gravity= "Center_vertical" > -  -  in         <Button -             Android:id= "@+id/button1" to Android:layout_width= "Wrap_content" + Android:layout_height= "Wrap_content" - Android:text= "button" /> the     </Relativelayout> *      $ </LinearLayout>

1 <LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"2 Android:layout_width= "Fill_parent"3 Android:layout_height= "Fill_parent"4 android:orientation= "Horizontal" >5 6     <Button7         Android:layout_width= "Wrap_content"8 Android:layout_height= "Wrap_content"9 Android:text= "AAA" />Ten  One     <LinearLayout A         android:layout_gravity= "Center_vertical" - Android:layout_width= "Fill_parent" - Android:layout_height= "Wrap_content" > the  -         <Button -             Android:layout_width= "Wrap_content" - Android:layout_height= "Wrap_content" + Android:text= "AAA" /> -     </LinearLayout> +  A </LinearLayout>


Android:layout_gravity and Android:gravity

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.