Android常用的五大布局:LinearLayout/RelativeLayout/AbsoluteLayout/ TableLayout/FrameLayout
来源:互联网 发布:snmp网络拓扑发现 编辑:程序博客网 时间:2024/06/18 05:11
LinearLayout线性布局:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="match_parent" android:orientation="vertical" ><!-- layout_:是控件本身的位置等属性的体现; 去掉layout_:则是指控件自身的内容位置等属性的体现 --> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" android:text="按钮1" /><!-- gravity:可以用“/”组合使用 --> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="right|center_vertical" android:text="按钮2" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="按钮3" /><!-- weightSum:权重,把总空间减去各个控件所占空间分成权重所给的n份,下面的控件的layout_weight属性给几,该控件就多占剩余空间(权重)的几份,也可以不写weightSum属性,那么,下面的各个控件的layout_weight属性值的和,就是剩余权重的总量 --> <!-- <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" android:weightSum="2"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="按钮a" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="按钮b" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="按钮c" /> </LinearLayout> --> <!-- 控件动态占据空间演示,这里让按钮b根据按钮c是否存在,动态变化按钮b所占空间 --> <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="按钮a" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="按钮b" /><!-- visibility:能见度,gone为不可见,且不占据空间;invisible为不可见,但仍占据控件visible可见 --> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:visibility="gone" android:text="按钮c" /> </LinearLayout></LinearLayout>
RelativeLayout相对布局
<?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" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:text="进攻" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:text="左勾拳" /><!-- layout_alignParentRight:当前控件的右端与父容器右边对齐 --> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:text="右勾拳" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:text="逃跑" /><!-- android:layout_centerInParent="true"在父元素的中心位置 --> <Button android:id="@+id/btn_bisha" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="大绝招" /> <!-- android:layout_toLeftOf="@id/btn_bisha" 当前控件在指定控件的左侧, android:layout_alignTop="@id/btn_bisha" 当前控件与指定控件的顶部对齐 --> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toLeftOf="@id/btn_bisha" android:layout_alignTop="@id/btn_bisha" android:text="左" /> <!-- android:layout_above="@id/btn_bisha" 当前控件在指定控件的上面 ; android:layout_centerHorizontal="true" 当前控件水平居中--> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@id/btn_bisha" android:layout_centerHorizontal="true" android:text="上" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@id/btn_bisha" android:layout_alignBaseline="@id/btn_bisha" android:text="右" /> <!-- android:layout_below="@id/btn_bisha" 当前控件在指定控件的下面 --> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/btn_bisha" android:layout_centerHorizontal="true" android:text="下" /></RelativeLayout>
AblosuteLayout绝对布局(不常用)
<?xml version="1.0" encoding="utf-8"?><AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" ><!-- Android,左上角为原点,向右为x,向下为y --> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_x="60dp" android:layout_y="253dp" android:text="按钮" /></AbsoluteLayout>
TableLayout表格布局(不常用)
关于表格布局的一些常用样式属性
android:shrinkColumns 收缩列
android:stretchColumns 拉伸列
android:collapseColumns 隐藏列
android:layout_column 指定列(作用在列的身上)
android:layout_span 合并列(作用在列的身上)
TableRow单元行里的单元格的宽度小于默认的宽度时就不起作用,其默认是fill_parent,高度可以自定义大小
<?xml version="1.0" encoding="utf-8"?><TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:shrinkColumns="0" android:collapseColumns="0" > <TableRow android:layout_height="wrap_content" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="第一行, 0列" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="第一行, 1列" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="第一行, 2列" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="第一行, 3列" /> </TableRow> <TableRow android:layout_height="wrap_content" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="第二行, 0列" /><!-- android:layout_column指定列(作用在列的身上)android:layout_span合并列(作用在列的身上)注意:这两个属性alt+/不提示 --> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_column="2" android:layout_span="2" android:text="第二行, 1列" /> </TableRow></TableLayout>
FrameLayout帧布局(不常用)
<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <Button android:layout_width="300px" android:layout_height="300px" android:layout_gravity="center" android:text="最底部" /> <Button android:layout_width="150px" android:layout_height="150px" android:layout_gravity="center" android:text="中间" /> <Button android:layout_width="50px" android:layout_height="50px" android:layout_gravity="center" android:text="顶部" /></FrameLayout>
0 0
- Android常用的五大布局:LinearLayout/RelativeLayout/AbsoluteLayout/ TableLayout/FrameLayout
- Android五大布局对象 - FrameLayout,LinearLayout ,AbsoluteLayout,RelativeLayout,TableLayout.
- Android五大布局对象:FrameLayout,LinearLayout,AbsoluteLayout,RelativeLayout,TableLayout
- Android 五大布局对象---FrameLayout,LinearLayout ,AbsoluteLayout,RelativeLayout,TableLayout.
- Android五大布局对象---FrameLayout,LinearLayout ,AbsoluteLayout,RelativeLayout,TableLayout.
- 五大布局对象---FrameLayout,LinearLayout ,AbsoluteLayout,RelativeLayout,TableLayout.
- Android 布局(LinearLayout\TableLayout\RelativeLayout\AbsoluteLayout\FrameLayout)
- Android 布局(LinearLayout\TableLayout\RelativeLayout\AbsoluteLayout\FrameLayout)
- 【UI布局】浅谈android五大布局-FrameLayout、LinearLayout、AbsoluteLayout、RelativeLayout、TableLayout】
- android学习--Android五大布局对象---FrameLayout,LinearLayout,AbsoluteLayout,RelativeLayout,TableLayout.
- Android基础教程(二)之五大布局对象---FrameLayout,LinearLayout ,AbsoluteLayout,RelativeLayout,TableLayout.
- android基础学习<一>--->五大布局对象Framelayout,Linearlayout,Relativelayout,Tablelayout,AbsoluteLayout
- Android基础教程(二)之五大布局对象---FrameLayout,LinearLayout ,AbsoluteLayout,RelativeLayout,TableLayout.
- Android基础教程(二)之五大布局对象---FrameLayout,LinearLayout ,AbsoluteLayout,RelativeLayout,TableLayout.
- Android基础教程(二)之五大布局对象—FrameLayout,LinearLayout ,AbsoluteLayout,RelativeLayout,TableLayout
- Android基础教程(二)之五大布局对象---FrameLayout,LinearLayout ,AbsoluteLayout,RelativeLayout,TableLayout.
- Android基础教程之五大布局对象------FrameLayout,LinearLayout,AbsoluteLayout,RelativeLayout,TableLayout
- Android基础教程(二)之五大布局对象---FrameLayout,LinearLayout ,AbsoluteLayout,RelativeLayout,TableLayout.
- JAVA设计模式(十五)——解释器模式
- zoj_1241 Geometry Made Simple
- 使用C函数读取BMP格式图像
- H264 ES PS TS 流的区别
- hibernate 用spring实现jdbc事物管理
- Android常用的五大布局:LinearLayout/RelativeLayout/AbsoluteLayout/ TableLayout/FrameLayout
- 【连通图|边双连通分量+Tarjan+并查集】POJ-3694 Network(400+ms)
- HDFS新特性Centralized Cache Management介绍
- mysql定时备份脚本
- Android EGL_BAD_CONFIG error,配置EGLConfigChooser
- hdu2852 KiKi's K-Number 树状数组求第k大数
- windows下使用libxml2处理XML报文
- Hadoop 1.2.1升级2.6.0的一次崎岖之旅(包括Hive、HBase对应的升级)
- 蓝桥杯——安慰奶牛