Android notes: button center | horizontal center | vertical center (conclusion)

Source: Internet
Author: User

-In view of the examples of center-centered tasks, I would like to sum up my understanding here.

 

-Center: The Center is divided into two different layout methods! They are linearlayout andRelativeLayout.

-Center in the linearlayout layout: directly paste the source code

Note: In the Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" attribute, if the horizontal center is at least full screen on the width, if the vertical center is at the height, full screen is taken on the height.

 

<Linearlayout Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" Android: gravity = "center | center_horizontal | center_vertical"> // The preceding gravity attribute parameter: Center, center_horizontal is horizontally centered and center_vertical is vertical centered <button Android: Id = "@ + ID/binding_button" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: TEXT = "associate a new account"/> </linearlayout>

 

 

-Then, we will talk aboutRelativeCenter in layout:

 

<Relativelayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent"> <button Android: Id = "@ + ID/btngal" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: gravity = "center_horizontal" Android: textsize = "20sp" Android: layout_alignparentbottom = "true" Android: layout_centerhorizontal = "true" Android: text = "back to main interface"/> </relativelayout>

 

 

Simple Description

Android: gravity = "center_vertical": vertical center alignment

Android: gravity = "bottom": placed at the bottom of the container

Android: gravity = "center": placed in the center of the container

 

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.