Android学习 8-> 相对布局RelativeLayout
2015-06-17 10:36
267 查看
相对布局RelativeLayout:允许子元素指定它们相对于其父元素或兄弟元素的位置,这是实际布局中最常用的布局方式之一。由于灵活性大很多,当然属性也多,操作难度也大,属性之间产生冲突的的可能性也大,使用相对布局时要多做些测试。
其xml代码如下(当然也可以试试别的属性定义位置实现其效果):
上面的代码中<!-- -->中间的内容是注释内容。
对于相对布局的用法在之前的介绍中有了,就不再写出来了。
其xml代码如下(当然也可以试试别的属性定义位置实现其效果):
<span style="font-size:24px;"><?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" > <!-- android:layout_alignParentLeft="true" 由于相对布局默认的是从左上角开始放置,所有此属性可以不用设置 --> <Button android:id="@+id/btn1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:text="按钮1" /> <Button android:id="@+id/btn2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:text="按钮2" /> <Button android:id="@+id/btn3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="按钮3" /> <!-- android:layout_alignParentLeft="true" 由于此处默认从左边开始放置,所有可以不用设置 --> <Button android:id="@+id/btn4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:text="按钮4" /> <Button android:id="@+id/btn5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:text="按钮5" /> </RelativeLayout></span>
上面的代码中<!-- -->中间的内容是注释内容。
对于相对布局的用法在之前的介绍中有了,就不再写出来了。
相关文章推荐
- [Android] ScrollView滚动到底部和顶部的检测
- android GridView设置边框教程
- Android开发学习笔记:浅谈GridView
- Android ViewPager应用详解
- android中GridView的Adapter的getView()
- Android回调机制
- 如何修改Android手机的hosts
- Android中Bitmap缓存池
- Android项目:模仿ConvertView原理(ListView的getView方法)对View对象进行回收和复用
- Github android客户端源代码分析之一:环境搭建
- android多分辨率多密度下界面适配方案
- Android中对手机文件进行读写
- Android中的消息机制:Handler消息传递机制
- Android 应用中十大常见 UX 错误
- Android 百度地图开发之地图不刷新问题解决
- 【Android SDK Manager 无法更新】 解决方案
- Android数据传递的五种方法汇总
- android 应用程序Activity之间数据传递与共享的几种途径
- Android数据存储的五种方法汇总
- Android横屏竖屏切换的问题