欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

Android button 居中,androidbutton居中,在main.xml 或者

来源: javaer 分享于  点击 40182 次 点评:79

Android button 居中,androidbutton居中,在main.xml 或者


在main.xml 或者其他xml布局文件中布局Button的时候,选择Android:gravity="center_horizontal",意思是Place object in thehorizontal center of its container, not changing its size.我们用RelativeLayout布局,这样可以使不同的组件有对齐的方式。

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:Android="<a href="http://schemas.android.com/apk/res/android">http://schemas.android.com/apk/res/android"    Android:layout_width="fill_parent"    Android:layout_height="fill_parent">    <TextView Android:id="@+id/gallerytext"        Android:layout_width="fill_parent"        Android:layout_height="wrap_content">    </TextView>    <Gallery Android:id="@+id/gallery"        Android:layout_width="fill_parent"        Android:layout_height="wrap_content">    </Gallery>    <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="返回主界面"/></RelativeLayout>//该片段来自于http://byrx.net
相关栏目:

用户点评