Questions

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 )

Your Answers

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

Answers

Jorge
Mar 09 12 08:49:36
Gracias, me ha servido mucho no encontraba como centrar en realidad un botón.

chexmix
Feb 20 12 10:52:33
good one!! used it.

tushar bapte
Aug 10 11 08:45:30
nice article.........

zhao
Aug 08 11 07:51:22
nice~~

NN
Jan 27 11 10:53:00
Great!!

sekar
Dec 30 10 01:30:38
@ wajeed what do you mean exactly ?

wajeed shaikh
Sep 30 10 08:51:52
how through code

sekar
Sep 07 10 06:49:34
Thank you

raj
Mar 17 10 01:25:09
how to develop android in netbeans

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 :)