Your Open Source

QA  >>  Mobile Development  >>  Android

Android

center align position in android button

How to alignment the center position of the button in Android?

In the XML layout, can able to set the center postion by using the "android:layout_gravity", the sample XML code as below,

<button android:text="ClickMe"
    android:id="@+id/btClick"
    android:layout_width="100px"
    android:gravity="center_vertical|center_horizontal"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical|center_horizontal|center" >
</button>


Attribute usage,
  • android:gravity   >  align the text
  • android:layout_gravity > align the layout position of the element 
  • android:layout_width > width of the button
  • android:layout_height > hight of the button ( wrag_content sense autoresize by using text )

  • hits 974
  • datetime Oct 15 09 04:53:20
  • author Sekar
  • rating

Rating : 12345

Comments


Gert
Jan 19 10 03:43:07
Thx a lot ! Great Tutorial.
Gert
Belgium

Mubarak
Oct 16 09 06:45:19
It's really amazing article!!! keep it up

Quick Reply or Comments

Preview
Your Name:
Your Reply :
<> is a code tag
Enter the verification code: