13、从头学Android之RelativeLayout相对布局
16lz
2021-12-04
相对布局对于做Web开发来说再熟悉不过了,我们在用CSS+DIV的时候经常会用到这些类似的相对布局的,在设置某个DIV的位置的时候,我们时常会以一个DIV作为参考来设置的位置,废话不多说,直接看属性看实例。
属性名称 | 描述 |
android:layout_below | 摆放在指定组件的下边 |
android:layout_toLeftOf | 摆放在指定组件的左边 |
android:layout_toRightOf | 摆放在指定组件的右边 |
android:layout_alignTop | 以指定组件作为参考进行上对齐 |
android:layout_algnBottom | 以指定组件作为参照进行下对齐 |
android:layout_alignLeft | 以指定组件作为参考进行左对齐 |
android:layout_alignRight | 以指定组件 |
以上一节的例子再做一个相对布局实现的例子
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content"> <EditText android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_alignParentRight="true" android:layout_toRightOf="@+id/tv_username" android:id="@+id/txt_username"> </EditText> <EditText android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/txt_username" android:layout_alignLeft="@+id/txt_username" android:layout_alignParentRight="true" android:id="@+id/txt_password"></EditText> <TextView android:id="@+id/tv_username" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="用户名称" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:layout_marginTop="14dp"></TextView> <Button android:text="登录" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/txt_password" android:layout_alignParentRight="true" android:layout_alignLeft="@+id/txt_password" android:id="@+id/btn_login"></Button> <Button android:text="取消" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/txt_password" android:layout_alignRight="@+id/tv_username" android:id="@+id/btn_cacel"></Button> <TextView android:id="@+id/tv_password" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="用户密码" android:layout_centerVertical="true" android:layout_toLeftOf="@+id/txt_password"></TextView> </RelativeLayout>
实例效果:
更多相关文章
- Android(安卓)应用程序基础
- Static interface methods are only supported starting with An
- 第三部分:Android(安卓)应用程序接口指南---第一节:应用程序组件--
- Android设备之间通过Wifi通信的示例代码
- Android(安卓)UI学习组件概述
- 《Android/OPhone开发完全讲义》连载(6):为TextView组件加上边框
- Andropid自定义组件-坐标详解
- Android基础和运行机制
- Android(安卓)1.5和Android(安卓)2.1在相对布局(RelativeLayout)上