16.GridView宫格的实现及其显示其…
2015-08-02 12:59
387 查看
1.Gridview布局(控件)
(1)xml布局中得实现:
android:id="@+id/gridview"
android:background="#f0f2f1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="90dp"
android:gravity="center"
android:horizontalSpacing="2dp"
android:numColumns="auto_fit"
android:stretchMode="columnWidth"
android:verticalSpacing="3dp" "
>
(2)GridView的item实现
http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
android:id="@+id/itemImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true" >
2.activity
的实现
//1.声明存放图片id和显示的名称
private String texts[] = null;
private int images[] = null;
//2.主要实现(在OnCreate()中实现)
//九宫格
images = new int[] {
R.drawable.feizhi, R.drawable.suliao,
R.drawable.jiaju,
R.drawable.jinshu, R.drawable.boli,
R.drawable.buliao,
R.drawable.dianqi, R.drawable.qidai };
texts = new String[] { "废纸系列",
"塑料系列", "家具系列", "金属系列", "玻璃系列", "布料系列",
"电器系列",
"期待" };
GridView gridview =
(GridView) findViewById(R.id.gridview);
ArrayList> lstImageItem =
new ArrayList>();
for (int i = 0; i < 8; i++)
{
HashMap map =
new HashMap();
map.put("itemImage",
images[i]);
map.put("itemText",
texts[i]);
lstImageItem.add(map);
}
SimpleAdapter saImageItems =
new SimpleAdapter(this, lstImageItem,// 数据源
R.layout.grid_item,//
显示布局
new
String[] { "itemImage" }, new int[] { R.id.itemImage });
gridview.setAdapter(saImageItems);
gridview.setOnItemClickListener(new
ItemClickListener());
(PS点击事件见下篇文章)
(1)xml布局中得实现:
android:id="@+id/gridview"
android:background="#f0f2f1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="90dp"
android:gravity="center"
android:horizontalSpacing="2dp"
android:numColumns="auto_fit"
android:stretchMode="columnWidth"
android:verticalSpacing="3dp" "
>
(2)GridView的item实现
http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
android:id="@+id/itemImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true" >
2.activity
的实现
//1.声明存放图片id和显示的名称
private String texts[] = null;
private int images[] = null;
//2.主要实现(在OnCreate()中实现)
//九宫格
images = new int[] {
R.drawable.feizhi, R.drawable.suliao,
R.drawable.jiaju,
R.drawable.jinshu, R.drawable.boli,
R.drawable.buliao,
R.drawable.dianqi, R.drawable.qidai };
texts = new String[] { "废纸系列",
"塑料系列", "家具系列", "金属系列", "玻璃系列", "布料系列",
"电器系列",
"期待" };
GridView gridview =
(GridView) findViewById(R.id.gridview);
ArrayList> lstImageItem =
new ArrayList>();
for (int i = 0; i < 8; i++)
{
HashMap map =
new HashMap();
map.put("itemImage",
images[i]);
map.put("itemText",
texts[i]);
lstImageItem.add(map);
}
SimpleAdapter saImageItems =
new SimpleAdapter(this, lstImageItem,// 数据源
R.layout.grid_item,//
显示布局
new
String[] { "itemImage" }, new int[] { R.id.itemImage });
gridview.setAdapter(saImageItems);
gridview.setOnItemClickListener(new
ItemClickListener());
(PS点击事件见下篇文章)
相关文章推荐
- 2.JASP_DOM解析xml基本思路总结
- 1.jsp+servlet+mysql建站基本思路…
- 30.正则表达式(1)
- 4.xml 解析
- 3.利用jasp进行dom方式解析
- 2.xml入门
- 1.xml入门
- 3.JavaScript 基础知识学习
- 2.JavaScript简单了解
- 1.JS实现获取IP信息,包括归属地,…
- 15.对话框和浮动Activity
- 14.Android端请求服务器端的数据Ht…
- 13.Android提交数据到服务器HttpCl…
- Android--获取当前系统时间
- 29.IO学习——总结(1)
- Android SQLite学习指南
- 28.IO学习——打印流
- 27.IO学习——Properties
- 26.IO学习——File类
- 25.IO学习——流的操作规律总结(重…