四大布局

来源:互联网 发布:org.apache报错 编辑:程序博客网 时间:2024/04/28 14:06

一、 线性布局 (LinearLayout)
以线性方向显示它的子视图,垂直或水平。

android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical"

layout_width=”match_parent”:当前控件大小和父布局大小一样;
layout_height=”wrap_content”:当前控件大小刚好能包裹里面的内容;
layout_weight=”1”:视图权重(比例),一般指定上面两个中一个为0;
android:layout_gravity=”top”:控件在界面上的位置,也就是在布局中的对齐方式。
android:gravity=”top”:(文字)在控件里的位置。
android:layout_margin=”50dp”:控件离父布局左、上、右的距离。
android:layout_marginTop=”50dp”:控件离父布局上边缘的距离。
android:layout_marginStart=”50dp”
android:layout_marginEnd=”50dp”:控件离父布局左右边缘距离;
android:cursorVisible=”true”:光标可见;
android:textColorLink=”@android:color/holo_blue_light”:文字链接的颜色;
android:maxLines=”5”:文本框里最大行数;
android:lines=”5”:精确的指定行数;
android:maxHeight=”50dp”:指定最大屏幕像素高度;
android:scrollHorizontally=”true”:文本是否允许超过布局;
android:singleLine=”true”:单行显示;
android:selectAllOnFocus=”true”:选中焦点所在框所有的内容,比如浏览器地址。
android:includeFontPadding=“true”:设置文本是否包含顶部和底部额外空白;
android:inputMethod为:文本指定输入法,需要完整的包名;
android:linksClickable:设置链接是否可以点击;
android:lineSpacingExtra:设置行间距。;
android:shadowColor指定文本阴影的颜色,需要与shadowRadius一起使用;
android:textAppearance:设置文字外观。比如“?android:attr/textAppearanceLargeInverse”;
android:textColorHighlight被选中文字的底色,默认为蓝色 ;
android:textColorHint设置提示信息文字的颜色,默认为灰色。与hint一起使用;
android:textScaleX:设置文字之间间隔,默认为1.0f;
android:textStyle:设置字形(bold(粗体) 0, italic(斜体) 1, bolditalic(又粗又斜) 2)可以设置一个或多个,用“|”隔开 ;
android:inputType:指定输入的类型,比如phone;
android:hint=”提示性文字”:文本框为空时的提示文字。
(以后慢慢补充。。。)
二、 相对布局(RelativeLayout)
以相对位置显示显示子视图。优点是可以消除嵌套视图组。
常用属性:来自网上的资源
http://www.douban.com/note/97496783/
第一类:属性值为true或false
android:layout_centerHrizontal 水平居中
android:layout_centerVertical 垂直居中
android:layout_centerInparent 相对于父元素完全居中
android:layout_alignParentBottom 贴紧父元素的下边缘
android:layout_alignParentLeft 贴紧父元素的左边缘
android:layout_alignParentRight 贴紧父元素的右边缘
android:layout_alignParentTop 贴紧父元素的上边缘
android:layout_alignWithParentIfMissing 如果对应的兄弟元素找不到的话就以父元素做参照物

第二类:属性值必须为id的引用名“@id/id-name”android:layout_below 在某元素的下方android:layout_above 在某元素的的上方android:layout_toLeftOf 在某元素的左边android:layout_toRightOf 在某元素的右边android:layout_alignTop 本元素的上边缘和某元素的的上边缘对齐android:layout_alignLeft 本元素的左边缘和某元素的的左边缘对齐android:layout_alignBottom 本元素的下边缘和某元素的的下边缘对齐android:layout_alignRight 本元素的右边缘和某元素的的右边缘对齐第三类:属性值为具体的像素值,如30dip,40pxandroid:layout_marginBottom 离某元素底边缘的距离android:layout_marginLeft 离某元素左边缘的距离android:layout_marginRight 离某元素右边缘的距离

三、 表格布局(TableLayout)
以表格显示子视图元素,以行和列标识一个视图的位置。

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"        android:layout_width="match_parent"        android:layout_height="match_parent">        <TableRow >            <TextView                 android:layout_height="wrap_content"                android:text="Text"/>            <EditText                 android:layout_height="wrap_content"                android:hint="Hint"/>        </TableRow>        <TableRow >            <TextView                 android:layout_height="wrap_content"                android:text="Text"/>            <EditText                 android:layout_height="wrap_content"                android:hint="Hint"/>        </TableRow>        <TableRow >            <Button                 android:layout_height="wrap_content"                android:text="Button"                android:layout_span="2"/>        </TableRow>    </TableLayout>

常用属性:
android:collapseColumns:以第0行为序,隐藏指定的列;
android:collapseColumns=0,2:把第0和第2列去掉,为空时独占一行;
android:shrinkColumns:以第0行为序,自动延伸指定的列填充可用部分,但是ayoutRow里面的控件还没有布满布局时,shrinkColumns不起作用;当LayoutRow布满控件时,设置shrinkColumns=2(比如是内容较多的一个单元格),控件自动向垂直方向填充空间;
android:stretchColumns:以第0行为序,尽量把指定的列填充空白部分;
android:layout_column ——-该单元格在第几列显示;
android:layout_span ——-该单元格占据列数,默认为1;

四、 框架布局(FrameLayout)
所有的控件都会摆放在布局的左上角。
FrameLayout布局里面android:layout_margin的各种属性必须依赖于android:layout_gravity,所以必须设定view的layout_gravity属性。

0 0
原创粉丝点击