RelativeLayout初步了解
2015-10-14 00:35
344 查看
特点:按组件的相对位置来多布局,如某个组件在某个组件的上下左右。常用属性:
代码示意:
XML属性 | 描述 |
android:layout_above | 指定该组件在某个组件上方 |
android:layout_below | 指定该组件在某个组件下方 |
android:layout_toLeftOf | 指定该组件在某个组件左边 |
android:layout_toRightOf | 指定该组件在某个组件的右边 |
android:layout_centerInParent | 指定该组件在父组件的中间 |
android:layout_centerVertical | 垂直居中 |
android:layout_centralHorizontal | 水平居中 |
android:layout_alignRight | 指定这个组件和哪个组件左边对齐 |
android:layout_alignLet | 指定这个组件和哪个组件右边对齐 |
android:layout_alignBottom | 指定这个组件和哪个组件底端对齐 |
android:layout_alignTop | 指定这个组件和哪个组件顶端对齐 |
android:layout_alignParentRight | 用于指定该组件是否与父控件右端对齐 |
android:layout_alignParentLeft | 指定该组件是否与父控件左端对齐 |
android:layout_alignParentTop | 指定该组件是否与父控件顶端对齐 |
android:layout_alignParentDown | 指定该组件是否与父控件下面对齐 |
<?xmlversion="1.0"encoding="utf-8"?>
<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/btn_center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="中"/>
<Button
android:id="@+id/btn_up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/btn_center"
android:layout_alignLeft="@+id/btn_center"
android:text="上"/>
<Button
android:id="@+id/btn_down"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/btn_center"
android:layout_centerHorizontal="true"
android:text="下"/>
<Button
android:id="@+id/btn_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/btn_center"
android:text="左"/>
<Button
android:id="@+id/btn_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btn_center"
android:layout_toRightOf="@+id/btn_center"
android:text="右"/>
</RelativeLayout>
<?xmlversion="1.0"encoding="utf-8"?>
<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/btn_center1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="中"/>
<Button
android:id="@+id/btn_left1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/btn_center1"
android:text="左"/>
<Button
android:id="@+id/btn_right1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btn_left1"
android:layout_alignParentRight="true"
android:text="右"/>
<Button
android:id="@+id/btn_left2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/btn_center1"
android:text="左"/>
<Button
android:id="@+id/btn_right2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btn_left2"
android:layout_alignParentRight="true"
android:text="右"/>
</RelativeLayout>
相关文章推荐
- VISTA或WIN7下使用立体声混音作为录音来源时,如何通过编程方式去除或加入麦克风的输入
- VS中的解决方案设置--文件结构
- mysql客户端操作 简数据库建立
- 闭包
- 硬造的轮子趟过的坑--浮点型转字符串函数
- ubuntu安装配置JDK(亲测)
- iOS简介
- handler机制理解
- mysql中的order by
- 黑马程序员——Gui
- internquestions
- SparkSQL的解析详解
- LA3357 Pinary
- mysql宽字符注入
- SQLite的优化方案
- HDU 2203 亲和串
- 【mysql】Innodb三大特性之double write
- html5toexe
- FileUtils
- hdu 1556 Color the ball