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

来源:互联网 发布:java项目视频 编辑:程序博客网 时间:2024/06/05 18:21

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 )
原创粉丝点击