Android开发总结笔记 GirdLayout(网格布局) 1-1-5
2015-09-22 16:33
543 查看
GridLayout的继承结构
网格布局是andorid4.0后才出来的一个布局管理器,不过现在v7包里面有兼容的
网格布局可以指定行数和列数
下面来试试这些属性
效果图
修改一下方向
发现问题
貌似在垂直(vertical)的时候行数(rowCount)才会起作用
而在水平(horizontal)的时候行数(columnCount)会起作用
给第二个imageview设置了android:layout_columnSpan
因为只有两列所以就独占一行。其他的就被挤下去了
现在给第二个(深绿)imageview设置android:layout_rowSpan
因为深绿的那个跨了两行,所以后面的也被挤下去了
android:layout_row和android:layout_column就不做介绍了,看描述就知道
GridLayout.Spec
GridLayout.Spec可以指定组件所在的行数和列数。
网上抄的一段关于创建计算器界面的代码,可以看出使用了GridLayout.Spec来对组件进行排版
因为不怎么常用,所以就在这里简单提一下
网格布局是andorid4.0后才出来的一个布局管理器,不过现在v7包里面有兼容的
网格布局可以指定行数和列数
下面来试试这些属性
<GridLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnCount="2"
android:orientation="horizontal">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@android:color/holo_blue_bright"/>
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@android:color/holo_green_dark"/>
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@android:color/holo_red_dark"/>
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@android:color/holo_purple"/>
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@android:color/holo_green_light"/>
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@android:color/holo_orange_dark"/>
</GridLayout>
效果图
修改一下方向
<GridLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:rowCount="2"
android:orientation="vertical">
发现问题
貌似在垂直(vertical)的时候行数(rowCount)才会起作用
而在水平(horizontal)的时候行数(columnCount)会起作用
<GridLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnCount="2"
android:orientation="horizontal">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@android:color/holo_blue_bright"/>
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_columnSpan="2"
android:background="@android:color/holo_green_dark"/>
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@android:color/holo_red_dark"/>
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@android:color/holo_purple"/>
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@android:color/holo_green_light"/>
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@android:color/holo_orange_dark"/>
</GridLayout>
给第二个imageview设置了android:layout_columnSpan
因为只有两列所以就独占一行。其他的就被挤下去了
现在给第二个(深绿)imageview设置android:layout_rowSpan
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_rowSpan="2"
android:background="@android:color/holo_green_dark"/>
因为深绿的那个跨了两行,所以后面的也被挤下去了
android:layout_row和android:layout_column就不做介绍了,看描述就知道
GridLayout.Spec
GridLayout.Spec可以指定组件所在的行数和列数。
GridLayout.SpecrowSpec=GridLayout.spec(i/4+2);
GridLayout.SpeccolumnSpec=GridLayout.spec(i%4);
GridLayout.LayoutParamsparams=newGridLayout.LayoutParams(
rowSpec,columnSpec);
params.setGravity(Gravity.FILL|Gravity.BOTTOM);
layout.addView(bn,params);
网上抄的一段关于创建计算器界面的代码,可以看出使用了GridLayout.Spec来对组件进行排版
因为不怎么常用,所以就在这里简单提一下
相关文章推荐
- android EditText在输入的时候输入框上方出现悬浮文字提示
- Android Canvas使用
- android studio问题汇总
- Android如何避免切换至SurfaceView时闪屏(黑屏闪一下)以及黑屏移动问题
- Android编码规范总结
- android圆角按钮
- android图片:多选相册的实现
- android 原型模式
- Android Jpush的集成
- Android Drawable Resource学习(二)、BitmapDrawable和Bitmap
- Caused by: java.lang.SecurityException: Unable to find app for caller android.app.ApplicationThreadP
- Android ProgressBar实现加载进度条
- Android Spinner 下拉列表
- Android GridView 二维布局界面
- Android DatePicker和TimePicker
- Android 监听器
- Android 数据适配器
- Androidmanifest.xml配置文件
- Android Intent实现页面跳转
- Android布局