How to center the control in Android layout

Source: Internet
Author: User

There are two different scenarios, in two different layout modes: LinearLayout andRelativeLayout

1. LinearLayout

a). android:layout_gravity= "Center_horizontal" means that the layout is centered horizontally in the parent layout, at which point the parent layout must have the android:orientation= "vertical" property;

b). android:layout_gravity= "center_vertical" means that the layout is centered vertically in the parent layout, at which point the parent layout must be set to android:orientation= "Horizontal" Property (the default is the property), and the height of its parent layout should be set to Android:layout_height= "Fill_parent" property;

2. Relativelayout

Property value is True or False

a). android:layout_centerhrizontal controls are centered horizontally in the parent layout
b). android:layout_centervertical controls are centered vertically in the parent layout
c). Android:layout_centerinparent control is completely centered relative to the parent element

To be clear here, do you want the content in the control to be centered horizontally, or is it centered horizontally in the parent control,

a). Let the content inside the TextView be centered horizontally: android:gravity= "Center_horizontal"

b). Let the TextView control be centered horizontally in its parent layout android:layout_gravity= "Center_horizontal"

How to center the control in Android layout

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.