RlativeLayout(1)——根据父容器定位
来源:互联网 发布:java序列化和反序列化 编辑:程序博客网 时间:2024/06/06 07:01
单个控件属性(1)
layout_alignParentLeft(左对齐)
layout_alignParentRight(右对齐)
layout_alignParentTop(顶对齐)
layout_alignParentBottom(底对齐)
layout_centerHorizontal(水平居中)
layout_centerVertical(竖直居中)
layout_centerInParent(中央位置)
center(中央)align(对齐)horizontal(水平)vertical(垂直)
- 只有一个属性
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="match_parent" android:layout_width="match_parent"> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="centerInparent" android:layout_centerInParent="true" android:id="@+id/mainTextView2" android:textSize="10sp"/> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_centerHorizontal="true" android:text="centarHorizontal" android:textSize="10sp"/> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="alignParentLeft" android:layout_alignParentLeft="true" android:id="@+id/mainTextView1" android:textSize="10sp"/> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="alignParentRight" android:layout_alignParentRight="true" android:textSize="10sp"/> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="alignParentButtom" android:layout_alignParentBottom="true" android:textSize="10sp"/> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="centerVertial" android:layout_centerVertical="true" android:textSize="10sp"/> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="alignParentTop" android:layout_alignParentTop="true" android:textSize="10sp"/></RelativeLayout>
(为什么有的有id,有的没有?)
上面就是我在使用aide进行布局的结果,可以看到,在只有一个对父容器定位的属性的布局的时候,默认是在左边的。
- 两个属性
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="match_parent" android:layout_width="match_parent"> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="右上" android:textSize="25sp" android:layout_alignParentTop="true" android:layout_alignParentRight="true" android:id="@+id/mainTextView1"/> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="左上" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:textSize="25sp"/> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="中左" android:textSize="25sp" android:layout_centerVertical="true"/> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="左下" android:layout_alignParentLeft="true" android:textSize="25sp" android:layout_alignParentBottom="true"/> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="上中" android:textSize="25sp" android:layout_centerHorizontal="true" android:layout_alignParentTop="true"/> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_centerVertical="true" android:layout_alignParentRight="true" android:textSize="25sp" android:text="中右"/> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_centerHorizontal="true" android:textSize="25sp" android:layout_alignParentBottom="true" android:text="下中"/> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentBottom="true" android:textSize="25sp" android:text="右下"/> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:textSize="25sp" android:text="中间"/></RelativeLayout>
看的出来这个布局还是很好符合正常人的思维的,只要组合就可以把控件放在界面的各个方向。
这个就是控件在相对布局里面的一个简单布局方法(个人感觉适合和后面的兄弟控件组合使用)
- 总结
感觉其实这些属性都是很简单的布局理解,注意穿插使用不同的单个属性达到组合效果才是真正的优美布局该有的。而且属性的名称也并非完全没有规律,注意区分应该就能很好的掌握了。(属性的true和false有什么用?) - 还有一个好玩的:如果给控件不能共存的属性时(不如Right和Left同时为真)会怎么样?
阅读全文
0 0
- RlativeLayout(1)——根据父容器定位
- div+css基础——6.采用div定位技术对div进行排版(绝对定位,不指定父容器)
- div+css基础——7.采用div定位技术对div进行排版(绝对定位,指定父容器)
- 根据内核Oops 定位代码工具使用— addr2line 、gdb、objdump
- 根据ip定位
- 根据IP定位地理位置
- web根据地址定位
- 【Spring Framework 深入】—— IoC容器初始化 -> Bean定义资源的Resource定位
- 如何根据父级元素进行相对定位
- 父容器不根据内容自适应高度的解决方法
- Div父容器不根据内容自动撑…
- IE6相对父容器绝对定位的bug及其解决办法
- CSS学习总结:浮动、定位、父容器塌陷问题
- CSS学习总结:浮动、定位、父容器塌陷问题
- Spring源码阅读之IoC容器初始化1 -- Resource定位
- STL容器 — 顺序容器
- fixed不以body定位,相对于父级容器定位问题
- 根据内存提示定位错误代码
- mysql常见的面试题
- MySQL索引及查询优化书目录
- ORACLE内置函数大全补充(正则表达式函数)
- ActiveMQ与Spring的整合使用
- Tomcat修改server.xml的端口报出端口冲突
- RlativeLayout(1)——根据父容器定位
- D
- closeEvent窗口:忽略状态还是确定执行
- ngrok配置
- [MFC]获得程序所在路径
- Load和Initialize往死了问是一种怎样的体验
- android 自定义圆形的ImageView
- android相关adb命令汇总
- hdu 6103 Kirinriki