Android布局常用属性

来源:互联网 发布:网络女主播闪现 编辑:程序博客网 时间:2024/06/06 19:52
布局
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 ,pxandroid: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 ,verticalandroid: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:顶部对齐
分享使人进步!
原创粉丝点击