Difference between gravity and layout_gravity in Android

Source: Internet
Author: User

Android: gravity: sets the content location on the control.

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

See the following:CodeSegment

Copy codeThe Code is as follows: <? XML version = "1.0" encoding = "UTF-8"?>
<! -- Android: gravity sets the text display position on the button, while Android: layout_gravity sets the display position of the button 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 = "show me on the right"
Android: layout_gravity = "right"/>
</Linearlayout>

The result is that the text of the button is displayed on the right, and the button is displayed on the right of the screen. The running result is as follows:

Related Article

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.