android 控件 网格视图(GridView)
来源:互联网 发布:nginx url 限制ip 编辑:程序博客网 时间:2024/04/27 14:09
1、继承关系和子类:
java.lang.Object
↳android.view.View
↳android.view.ViewGroup
↳android.widget.AdapterView<T extends android.widget.Adapter>
↳android.widget.AbsListView
↳android.widget.GridView
2、定义:
A view that shows items in two-dimensional scrolling grid. The items in the grid come from the ListAdapter associated with this view.
GridView是以九宫格方式展现子模块的最佳选择。
3、XML重要属性:
android:columnWidth Specifies the fixed width for each column.
android:gravity Specifies the gravity within each cell.
android:horizontalSpacing Defines the default horizontal spacing between columns.
android:numColumns Defines how many columns to show.
android:stretchMode Defines how columns should stretch to fill the available empty space, if any.
android:verticalSpacing Defines the default vertical spacing between rows.
4、重要方法:
相关xml属性的setter和getter函数
5、实战:
布局文件 activity_main.xml
参考2:http://www.tuicool.com/articles/JvMrEj
java.lang.Object
↳android.view.View
↳android.view.ViewGroup
↳android.widget.AdapterView<T extends android.widget.Adapter>
↳android.widget.AbsListView
↳android.widget.GridView
2、定义:
A view that shows items in two-dimensional scrolling grid. The items in the grid come from the ListAdapter associated with this view.
GridView是以九宫格方式展现子模块的最佳选择。
3、XML重要属性:
android:columnWidth Specifies the fixed width for each column.
android:gravity Specifies the gravity within each cell.
android:horizontalSpacing Defines the default horizontal spacing between columns.
android:numColumns Defines how many columns to show.
android:stretchMode Defines how columns should stretch to fill the available empty space, if any.
android:verticalSpacing Defines the default vertical spacing between rows.
4、重要方法:
相关xml属性的setter和getter函数
5、实战:
布局文件 activity_main.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <!-- 设置4列 --> <GridView android:id="@+id/GridView1" android:layout_width="match_parent" android:layout_height="wrap_content" android:numColumns="4" /></LinearLayout>
每一项的布局文件: items.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <ImageView android:id="@+id/image" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingLeft="10px" android:scaleType="fitCenter" /> <TextView android:id="@+id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:padding="5px" /></LinearLayout>java代码
package com.example.gridviewdemo;import java.util.ArrayList;import java.util.HashMap;import android.os.Bundle;import android.support.v7.app.ActionBarActivity;import android.widget.GridView;import android.widget.SimpleAdapter;/** * 介绍GridView的简单使用 * @author pengpeng * 2014年5月27日 23:54:27 * * */public class MainActivity extends ActionBarActivity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);//显示GridView的界面GridView gridView = (GridView) findViewById(R.id.GridView1);//准备数据 图标加文字int[] image = { R.drawable.ic_launcher, R.drawable.ic_launcher,R.drawable.ic_launcher, R.drawable.ic_launcher,R.drawable.ic_launcher, R.drawable.ic_launcher,R.drawable.ic_launcher, R.drawable.ic_launcher };String[] text = { "a", "b", "c", "d", "e", "f", "g", "h" };ArrayList<HashMap<String, Object>> imagelist = new ArrayList<HashMap<String, Object>>();for (int i = 0; i < image.length; i++) {HashMap<String, Object> map = new HashMap<String, Object>();map.put("image", image[i]);map.put("text", text[i]);imagelist.add(map);}//设置适配器SimpleAdapter simpleAdapter = new SimpleAdapter(this, imagelist,R.layout.items, new String[] { "image", "text" }, new int[] {R.id.image, R.id.title });//把适配器设置到GridView的一个实例上gridView.setAdapter(simpleAdapter);}}参考1:http://developer.android.com/intl/zh-cn/reference/android/widget/GridView.html
参考2:http://www.tuicool.com/articles/JvMrEj
0 0
- android 控件 网格视图(GridView)
- Android中的GridView网格视图控件
- Android UI控件详解-GridView(网格视图)
- Android控件之GridView 网格视图组件
- [控件]GridView网格视图
- Android 网格视图GridView
- android gridview网格视图
- 使用网格视图控件GridView
- Android中GridView网格视图
- Android—Gridview(网格视图)
- Android 网格视图(GridView) 实践
- 高级控件之网格视图(GridView)
- Android UI系统控件进阶(四)—网格视图控件GridView
- Android组件 网格视图(GridView)
- android 网格视图 GridView 通过SimpleAdapter实现
- Android基础之----GridView(网格视图)
- GridView网格视图
- 网格视图(GridView)
- HeapByteBuffer和DirectByteBuffer
- 使用FusionCharts时利用XML/JSON属性加载外部LOGO
- 查看版本
- linux 防火墙
- javascript 构造StringBuffer对象
- android 控件 网格视图(GridView)
- Linux下的多线程编程(linux pthread)
- 百度url参数分别代表什么意思?
- poj Set Definition
- android 控件 卷轴视图(ScrollView)
- 回调函数之 schedule定时器
- 修改系统文件访问权限的方法
- IPicture
- 3、从头学Android之Activity生命周期