GridView和Gallery基本用法
来源:互联网 发布:上门修手机 知乎 编辑:程序博客网 时间:2024/05/17 09:22
GridView和Gallery类似
参考android 官方api.
步骤:
1.定义一以GridView为根标签的xml视图文件。
2.创建ImageAdapter类,继承于BaseAdapter
3.在ImageAdapter类中的getView()方法中增加视图显示的条件
例:
imageView=new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(60,60));//缺少红色部分容易出错
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setImageResource(mThumbIds[parament]);
4.在主activity中调用GridView每一格的点击事件
image.setItemOnClickListener(new ItemOnClickListener(){...});
5.设置背景(选择)
例:
a)新建arrs.xml文件
b)关联<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="HelloGallery">
<attr name="android:galleryItemBackground" />
</declare-styleable>
</resources>//可以在ImageAdapter类初始化中关联
TypedArray attr = mContext.obtainStyledAttributes(R.styleable.HelloGallery);
mGalleryItemBackground = attr.getResourceId(
R.styleable.HelloGallery_android_galleryItemBackground, 0);
attr.recycle();
- GridView和Gallery基本用法
- Android:Gallery,ImageSwitcher 和GridView用法
- Gallery和GridView浅析
- Gallery和GridView 小结
- Gallery和GridView浅析
- Gallery和GridView
- Gallery和GridView浅析
- android之GridView和Gallery
- GridView的基本用法和属性
- Gridview的基本用法
- GridView 基本用法
- GridView的基本用法
- Android的GridView和Gallery结合Demo
- Android的GridView和Gallery结合Demo
- GridView Gallery Spinner AutoCompleteTextView和ExpandableListView
- Android:ImageSwitcher 和 Gallery用法
- ASP.net GridView基本用法
- 画廊视图(Gallery)的功能和用法
- Android中SharedPreferences(共享参数)用法
- SurfaceView的学习01
- 编程真难。。。
- IOS获取屏幕分辨率
- Windows7帮你监控记录电脑使用
- GridView和Gallery基本用法
- 几种方法创建cocos2d游戏菜单
- ZOJ 1406.Jungle Roads
- php 根据两点的经纬度计算距离
- Android 自定义ContentProvider
- Eclipse中的文本编码设置
- 【对转载进行了部分解释】CRoutingZone的实现机制 以及 process()中一些函数的意义
- C语言中通过分隔符来截取字符串
- java 设计模式学习笔记十二 command命令设计模式