Second, the difference between gravity and layout_gravity in Android

Source: Internet
Author: User

Android:gravity: Sets the content location above the control itself

Android:layout_gravity: Sets the display position of the control itself relative to the parent control.

Look at the following code snippet

<?XML version="1.0"encoding="Utf-8"?>
<!--Android:gravity Sets the display position of the text above the button, and android:layout_gravity sets the position where the button appears in the layout. -
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
Android:orientation
="Vertical"
Android:layout_width
="fill_parent"
Android:layout_height
="fill_parent">
<Button android:layout_width="250dip"
Android:gravity
=" Right"
Android:layout_height
="wrap_content"
Android:text
="I'm right on display ."
Android:layout_gravity
=" Right"/>
</LinearLayout>

The result is that the text of the button appears on the right, and the button appears on the right side of the screen, running as follows

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.