当前位置:首页 > 嵌入式 > 嵌入式软件
[导读] 1. [代码]main.xml 01 <?xml version="1.0" encoding="utf-8"?> 02 <RelativeLayout

 1. [代码]main.xml

01 <?xml version="1.0" encoding="utf-8"?>
[!--empirenews.page--]
02 <RelativeLayout xmlns:Android="http://schemas.android.com/apk/res/android"
[!--empirenews.page--]
03     Android:layout_width="fill_parent"
[!--empirenews.page--]
04     Android:layout_height="fill_parent">
[!--empirenews.page--]
05     <TextView Android:id="@+id/gallerytext"
[!--empirenews.page--]
06         Android:layout_width="fill_parent"
[!--empirenews.page--]
07         Android:layout_height="wrap_content">
[!--empirenews.page--]
08     </TextView>
[!--empirenews.page--]
09     <Gallery Android:id="@+id/gallery"
[!--empirenews.page--]
10         Android:layout_width="fill_parent"
[!--empirenews.page--]
11         Android:layout_height="wrap_content">
[!--empirenews.page--]
12     </Gallery>
[!--empirenews.page--]
13     <Button Android:id="@+id/btngal"
[!--empirenews.page--]
14         Android:layout_width="wrap_content"
[!--empirenews.page--]
15         Android:layout_height="wrap_content"
[!--empirenews.page--]
16         Android:gravity="center_horizontal"
[!--empirenews.page--]
17         Android:textSize="20sp"
[!--empirenews.page--]
18         Android:layout_alignParentBottom="true"
[!--empirenews.page--]
19         Android:layout_centerHorizontal="true"
[!--empirenews.page--]
20         Android:text="返回主界面"/>
[!--empirenews.page--]
21 </RelativeLayout>
[!--empirenews.page--]

2. [图片] 运行结果

3. [代码]简单说明

view sourceprint?

1 可以看到Button 与Gallery的对齐方式是居中对齐,也即Button 与Parent居中对齐。
2 另外,
[!--empirenews.page--]
3 Android:gravity="CENTER_VERTICAL“:这个是垂直居中对齐
4 Android:gravity="BOTTOM”:放在容器的底部
[!--empirenews.page--]
5 Android:gravity="CENTER“ :放在容器的中心
本站声明: 本文章由作者或相关机构授权发布,目的在于传递更多信息,并不代表本站赞同其观点,本站亦不保证或承诺内容真实性等。需要转载请联系该专栏作者,如若文章内容侵犯您的权益,请及时联系本站删除( 邮箱:macysun@21ic.com )。
换一批
延伸阅读
关闭