Android基础_3 Activity相对布局
2016-01-24 23:14
501 查看
相对布局要比前面讲的线性布局和表格布局要灵活一些,所以平常用得也是比较多的。相对布局控件的位置是与其周围控件的位置相关的,从名字可以看出来,这些位置都是相对的,确定出了其中一个控件的位置就可以确定另一个控件的位置了。
本次实验就是显示如下的activity:
其中只有2个button,1个textview,1个edittext。
在相对布局中,一般用到的控件属性解释如下:
在相对布局中有如下属性,解释如下:
android:layout_above 为将该控件的底部放在指定id控件的上方
android:layout_below 同理类似,将该控件的顶部放在指定id控件的下方
android:layout_toLeftOf 将该控件的右端紧挨着放在指定id控件的左端。
android:layout_toRightOf 将该控件的左端紧挨着放在指定id控件的右端
android:layout_alignParentRight 为true时将该控件右端与父控件右端对齐
android:layout_alignParentLeft 为true时将该控件左端与父控件左端对齐
android:layout_alignParentTop 为true时将该控件顶端与父控件顶端对齐
android:layout_alignParentBottom 为true时将该控件底端与父控件底端对齐
android:layout_alignBottom 将该控件底部与指定id控件底部控件对齐
android:layout_alignLeft 将该控件左边与指定id控件左边对齐
android:layout_alignRight 将该控件右边与指定id控件右边对齐
android:layout_alignTop 将该控件顶端与指定id控件顶端对齐
实现上面activity比较简单,其xml代码如下:
总结:activity的相对布局比较灵活,一些常见的属性也比较多,用得多自然就会了。
本次实验就是显示如下的activity:
其中只有2个button,1个textview,1个edittext。
在相对布局中,一般用到的控件属性解释如下:
在相对布局中有如下属性,解释如下:
android:layout_above 为将该控件的底部放在指定id控件的上方
android:layout_below 同理类似,将该控件的顶部放在指定id控件的下方
android:layout_toLeftOf 将该控件的右端紧挨着放在指定id控件的左端。
android:layout_toRightOf 将该控件的左端紧挨着放在指定id控件的右端
android:layout_alignParentRight 为true时将该控件右端与父控件右端对齐
android:layout_alignParentLeft 为true时将该控件左端与父控件左端对齐
android:layout_alignParentTop 为true时将该控件顶端与父控件顶端对齐
android:layout_alignParentBottom 为true时将该控件底端与父控件底端对齐
android:layout_alignBottom 将该控件底部与指定id控件底部控件对齐
android:layout_alignLeft 将该控件左边与指定id控件左边对齐
android:layout_alignRight 将该控件右边与指定id控件右边对齐
android:layout_alignTop 将该控件顶端与指定id控件顶端对齐
实现上面activity比较简单,其xml代码如下:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="10px" > <TextView android:id="@+id/input" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/input_dis" tools:context=".MainActivity" /> <EditText android:id="@+id/edit" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@id/input" android:background="@android:drawable/editbox_background" /> <Button android:id="@+id/ok" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@id/edit" android:layout_alignParentRight="true" android:layout_marginLeft="10px" android:text="@string/ok" /> <Button android:id="@+id/cancel" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@id/edit" android:layout_toLeftOf="@id/ok" android:text="@string/cancel" /> </RelativeLayout>
总结:activity的相对布局比较灵活,一些常见的属性也比较多,用得多自然就会了。
相关文章推荐
- Android 加载图片优化(一)
- Android基础_2 Activity线性布局和表格布局
- Android学习小记
- 【转】如何用 Chrome for Android 做远程遥控 debugging
- ubuntu 14编译VCL for Android
- Android笔记 - Binder之请求注册Service组件
- Android中的LruCache缓存技术
- android平台Ormlite框架简易入门笔记
- Android v7 Toolbar的使用
- Android Studio 单元测试
- Android之AndroidStudio使用
- Android技巧2:登录注册模块解决方案
- android camera HAL: 请求的创建和提交
- Nexus 5 Android 6.0.1刷机、Root
- android studio 中的 包解析失败 以及the selected device is incompatible
- android:View的setTag和getTag使用
- Android的Java层系统服务
- Android初级自学笔记—json 数据解析
- Android获取应用程序的版本名称和版本号
- 寒假练习一