五大布局——相对布局
2015-08-18 20:17
281 查看
1.RelativeLayout属性
1.alignParentLeft Right Bottom Top 相对父空间的上下左右2.centerInParent centerVertical centerHorizontal
3.toLeftOf(R)=”@id/”……在 的左边 above below
4. alingleft(R,T,B)=”@id/”相对后边跟的ID的那个空间上下左右边对齐
5. layout_alignBaseline 基准线对齐
2.RelativeLayout布局的实现
alignParentLeft(R,B,T),centerInParent的实现
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="button1" android:id="@+id/button" android:layout_alignParentLeft="true" android:background="@color/red" ></Button> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:background="@color/red"></Button> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:background="@color/red" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:background="@color/red" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:background="@color/red"></Button> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:background="@color/red"/> </RelativeLayout>
2.toLeftOf(R),layout_above,layou_below
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="center" android:id="@+id/button"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toLeftOf="@id/button"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@id/button"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@id/button"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/button"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@id/button" android:layout_below="@id/button"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@id/button" android:layout_above="@id/button"/> </RelativeLayout>
3.alignLeft(R,T,B)
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:layout_width="200dp" android:layout_height="200dp" android:layout_centerInParent="true" android:id="@id/button" android:background="@color/red"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignRight="@id/button"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@id/button"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@id/button"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignTop="@id/button" android:layout_alignRight="@id/button"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@id/button" android:layout_alignBottom="@id/button"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@id/button"/> </RelativeLayout>
相关文章推荐
- HDU5386 Cover 果然还是暴力
- 透明窗体透明窗体 控件正常显示
- UIBarButtonItem 小记边
- UI总结之获取各种路径1
- 黑马程序员——视频学习过程5
- C语言之文件操作06——写数据到文本文件遇0停止
- 30 个免费的响应式 HTML5 CSS3 网站模板
- POJ 2186 Popular Cows
- Struct与Class的区别
- 【HDOJ 5400】Arithmetic Sequence
- 搭建Python HTTP服务
- 递归降序遍历目录层次结构,并按文件类型计数
- 递归降序遍历目录层次结构,并按文件类型计数
- 总线设备驱动模型
- 【Linux探索之旅】第一部分第五课:Unity桌面,人生若只如初见
- 集训第六周 古典概型 期望 D题 Discovering Gold 期望
- CODEVS 2055 集合划分
- “Adb connection Error:远程主机强迫关闭了一个现有的连接。”之我的解决方法。
- Android基础0818生命周期+LinearLayout+RelativeLayout
- Ubuntu:su切换用户时提示 su:认证失败