布局
1.布局分为线性布局(linearlayout),
表格布局(tablelayout),
网格布局(gridlayout),
帧布局(framelayout),
绝对布局(absolutelayout),
相对布局(relativelayout),
rtl布局(right to left),
其中,绝对布局不常用,网格布局与rtl布局是在Android 4.0后出现的。
2.共有的属性
layout_height : 控制当前控件在容器中所占高度;
layout_width : 控制当前控件在容器中所占宽度;
二者的取值范围:分为wrap_content , fill_parent ,match_parent ,
其中,它们三者的含义与区别:
wrap_content:强制将控件的大小扩展以显示控件的全部内容;
fill_parent:强制将控件的大小扩展到容器的最大大小;
match_parent:同fill_parent一样,区别在于后者在Android 2.2版本以下都可用,而前者不行;
一些固定值:dp ,sp ,mm ,px
android:layout_grivity:针对控件本身而言,设置当前控件在父容器中的位置,
可取值:top ,bottom ,left ,right ,center_vertical(垂直居中) ,center_horizontal (水平居中),center(居中),fill_vertical(垂直填充),fill_horizontal(水平填充)
特殊情况:当父容器的orientation被设置为vertical时,所有垂直方向的设置都将不起作用;而被设置为horizontal时,所有水平方向的设置也将不起作用。
android:layout_margin:控件的外边框
android:layout_marginTop:控件的上外边框
android:layout_marginButtom:控件的下外边框
orientation:容器中控件排列的方向,取值为horizontal ,vertical
android:gravity:针对此控件中的元素而言,控制控件在容器中的显示位置
android:id:有两种:@id/name 和 @+id/name ,区别在于前者作用用于引用,后者表示如果没有此属性,则会进行添加;
表格布局
android:shrinkColumns:某些列被收缩
android:stretchColumns:某些列被拉伸
android:collapseColumns:某些列被隐藏
android:layout_span:让某列跨列
网格布局
rowCount:指定布局中有多少行
columnCount:指定布局中有多少列
layout_rowSpan:设置此控件跨行
layout_columnSpan:设置控件跨列
绝对布局
layout_x 与 layout_y :控制控件的坐标
但由于屏幕大小和分辨率的变化,位置也会变化,所以不推荐使用
相对布局
android:layout_alignParentBottm:设置为true,则将该控件与父控件进行底部对齐
android:layout_alignParentLeft:设置为true,将该控件与父控件进行左对齐
android:layout_alignParentRight:设置为true,将该控件与父控件进行右对齐
android:layout_alignParentTop:设置为true,将改控件与父控件进行顶部对齐
android:layout_centerHorizontal:设置为true,将该控件水平居中
android:layout_centerVertical:设置为true,将该控件垂直居中
android:layout_centerInParent:设置为true,将该控件水平垂直居中
android:layout_above:将该控件设置为给定控件之上
android:layout_below:将该控件设置为给定控件之下
android:layout_toLeftOf:将该控件设置为给定控件的左边
android:layout_toRightOf:将该控件设置为给定控件的右边
android:layout_alignBaseline:将该控件的baseline与给定控件的baseline对齐
android:layout_alignBottom:将该控件跟给定控件底部对齐
android:layout_alignLeft:将该控件跟给定控件左对齐
android:layout_alignRight:将该控件跟给定控件右对齐
android:layout_alignTop:顶部对齐
分享使人进步!