GridLayout与TableLayout布局
来源:互联网 发布:阿里云应用镜像是什么 编辑:程序博客网 时间:2024/06/03 17:35
记录下GridLayout与TableLayout布局的一些知识点,这两个布局对比起来弄,感觉明显比较更能加深印象。
GridLayout的使用设置:
GridLayout 布局在 Level14才被支持,之前版本要使用的话,要按以下步骤设置:
1. import -> Existing Android Code Into Workspace2. 选择目录: 在sdk下的GridLayout目录
sdk\extras\android\support\v7\gridlayout
3. 勾选"Copy projects into workspace"
TableLayout 的一些不足:
至于有了TableLayout又搞个GridLayout的原因,简单试了下TableLayout,我认为至少有下面两个原因
1.不能同时向水平和垂直方向做控件的对齐
TableLayout继承了LinearLayout,因此只能向一个方向做控件的对齐。
2.不能跨行跨列
因为TableLayout,不明确指定包含多少行,多少列,而是通过向TableRow里面添加其他组件,每添加一个组件该表格就增加一列。
如果向TableLayout里面添加组件,那么该组件就直接占用一行。所以这种方式造成控件不能跨行跨列。
而GridLayout,则用columnCount设置列数后,增加的控件在超过列数后自动换行进行排列。
简单汇总下TableLayout的特点:
Shrinkable : 该列的宽度可以进行收缩,以使表格能够适应父容器的大小
Stretchable : 该列可以进行拉伸,以填满表格中空闲的空间
Collapsed : 该列将会被隐藏
GridLayout的特点:
android:layout_row : 固定显示在第几行。
android:layout_column : 固定显示在第几列,前面几列没控件的话就空着。
android:layout_rowSpan : 跨几行
android:layout_columnSpan: 跨几列
用GridLayout弄计算器的例子都烂大街了,自己写了个好玩的例子来展示下这两个布局:
代码如下:
- <?xml version="1.0" encoding="utf-8"?>
- <GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_gravity="center"
- android:orientation="vertical"
- android:rowCount="5"
- android:columnCount="4"
- android:background="#FFE4C4"
- >
- <ImageView
- android:layout_column="0"
- android:layout_gravity="left|top"
- android:layout_row="0"
- android:src="@drawable/emoji_436" />
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="left|top"
- android:layout_row="0"
- android:layout_column="1"
- android:layout_columnSpan="2"
- android:background="@drawable/chatfrom_bg_app_normal"
- android:text="我喜欢你......(表白进行中)"
- />
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="right|top"
- android:layout_row="1"
- android:layout_column="1"
- android:layout_columnSpan="2"
- android:background="@drawable/chatto_bg_focused"
- android:text="一公斤苹果等于多少克?"
- />
- <ImageView
- android:layout_column="3"
- android:layout_gravity="right|top"
- android:layout_row="1"
- android:src="@drawable/emoji_443" />
- <ImageView
- android:layout_column="0"
- android:layout_gravity="left|top"
- android:layout_row="2"
- android:src="@drawable/emoji_436" />
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="left|top"
- android:layout_row="2"
- android:layout_column="1"
- android:layout_columnSpan="2"
- android:background="@drawable/chatfrom_bg_app_normal"
- android:text="啊,1024..."
- />
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="right|top"
- android:layout_row="3"
- android:layout_column="1"
- android:layout_columnSpan="2"
- android:background="@drawable/chatto_bg_focused"
- android:text="嗯,你是一个好人.但..."
- />
- <ImageView
- android:id="@+id/imageView1"
- android:layout_column="3"
- android:layout_gravity="right|top"
- android:layout_row="3"
- android:src="@drawable/emoji_443" />
- <TableLayout
- android:id="@+id/tablelayout1"
- android:layout_row="4"
- android:layout_column="0"
- android:layout_columnSpan="4"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:shrinkColumns="1"
- android:stretchColumns="2">
- <!-- 在TableLayout中,在TableRow以外,直接添加的对象会独占一行 -->
- <Button android:text="上面GridLayout,下面是TableLayout"/>
- <TableRow>
- <TextView
- android:id="@+id/imageView222"
- android:background="@drawable/chatto_bg_voiceforward_focused"
- android:text="好人卡1" />
- <TextView
- android:id="@+id/imageView222"
- android:background="@drawable/chatto_bg_voiceforward_focused"
- android:text="好人卡2" />
- <TextView
- android:id="@+id/imageView222"
- android:background="@drawable/chatto_bg_voiceforward_focused"
- android:text="好人卡3" />
- </TableRow>
- </TableLayout>
- </GridLayout>
<?xml version="1.0" encoding="utf-8"?><GridLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center" android:orientation="vertical" android:rowCount="5" android:columnCount="4" android:background="#FFE4C4" > <ImageView android:layout_column="0" android:layout_gravity="left|top" android:layout_row="0" android:src="@drawable/emoji_436" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="left|top" android:layout_row="0" android:layout_column="1" android:layout_columnSpan="2" android:background="@drawable/chatfrom_bg_app_normal" android:text="我喜欢你......(表白进行中)" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right|top" android:layout_row="1" android:layout_column="1" android:layout_columnSpan="2" android:background="@drawable/chatto_bg_focused" android:text="一公斤苹果等于多少克?" /> <ImageView android:layout_column="3" android:layout_gravity="right|top" android:layout_row="1" android:src="@drawable/emoji_443" /> <ImageView android:layout_column="0" android:layout_gravity="left|top" android:layout_row="2" android:src="@drawable/emoji_436" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="left|top" android:layout_row="2" android:layout_column="1" android:layout_columnSpan="2" android:background="@drawable/chatfrom_bg_app_normal" android:text="啊,1024..." /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right|top" android:layout_row="3" android:layout_column="1" android:layout_columnSpan="2" android:background="@drawable/chatto_bg_focused" android:text="嗯,你是一个好人.但..." /> <ImageView android:id="@+id/imageView1" android:layout_column="3" android:layout_gravity="right|top" android:layout_row="3" android:src="@drawable/emoji_443" /> <TableLayout android:id="@+id/tablelayout1" android:layout_row="4" android:layout_column="0" android:layout_columnSpan="4" android:layout_width="fill_parent" android:layout_height="wrap_content"android:shrinkColumns="1" android:stretchColumns="2"><!-- 在TableLayout中,在TableRow以外,直接添加的对象会独占一行 --><Button android:text="上面GridLayout,下面是TableLayout"/><TableRow><TextView android:id="@+id/imageView222" android:background="@drawable/chatto_bg_voiceforward_focused" android:text="好人卡1" /><TextView android:id="@+id/imageView222" android:background="@drawable/chatto_bg_voiceforward_focused" android:text="好人卡2" /> <TextView android:id="@+id/imageView222" android:background="@drawable/chatto_bg_voiceforward_focused" android:text="好人卡3" /></TableRow></TableLayout> </GridLayout>
MAIL: xcl_168@aliyun.com
BLOG: http://blog.csdn.net/xcl168
0 0
- GridLayout与TableLayout布局
- GridLayout与TableLayout布局
- GridLayout与TableLayout布局
- GridLayout与TableLayout布局
- GridLayout,TableLayout
- Android学习 9-> 表格布局TableLayout和网格布局GridLayout
- Android常用布局及属性--FrameLayout、TableLayout、 GridLayout、AbsoluteLayout、RelativeLayout
- TableLayout 与GridLayout 列扩展和行扩展
- GridLayout和TableLayout
- Android GridLayout、TableLayout使用
- gridlayout布局
- GridLayout布局
- GridLayout布局
- 【Android】六大布局——LinearLayout、RelativeLayout、TableLayout、AbsoluteLayout、FrameLayout、GridLayout
- TableLayout布局
- TableLayout布局
- TableLayout布局
- 01-10:LinearLayout与TableLayout嵌套布局
- http://www.cnblogs.com/interdrp/p/3785164.html
-  |"|&|<|>等html字符转义
- mac的sqlite管理工具:SQLiteManager
- Service 之 AIDL
- DevStack 安装 OpenStack 多节点(Juno+Neutron+ML2+VXLAN)
- GridLayout与TableLayout布局
- PAT A1037 Magic Coupon 记得把0剔除哦
- Content Provider Basics
- 大数据架构:flume-ng+Kafka+Storm+HDFS 实时系统组合
- 静态方法不能直接调用实例方法和变量,但可以间接调用(即在静态方法中创建类的实例,然后调用)
- 金融IC卡行业应用的发展--困境(1)
- JAVA和ANT的安装及环境变量的设置
- Content Provider 之Creating a Content Provider
- 网页关闭(解决window.close在火狐下不兼容问题)