基于BaseAdapter的GridView设置ImageView大小
基于BaseAdapter的GridView设置ImageView大小
网上找了好多,都是基于SimpleAdapter的,本身在Item.xml中就对ImageView设置了id,而基于BaseAdapter的几乎没有,搞了好长时间一直有问题,这里参考网友的一篇文章(http://www.cnblogs.com/over140/archive/2010/09/14/1825649.html),成功实现了这一功能。
public View getView(int position, View subView, ViewGroup viewGroup) {
ImageView imageView;
if(subView ==null)
{
imageView = new ImageView(GridViewActivity.this);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
//设置ImageView高度
GridView.LayoutParams params = new GridView.LayoutParams(LayoutParams.MATCH_PARENT,screenWidth/4); //(1)
imageView.setLayoutParams(params);
}else{
imageView = (ImageView) subView;
}
Bitmap bm = BitmapFactory.decodeFile("sdcard/PictureTrans/"+MainActivity.username+"/thumbnails/"+MainActivity.localImgList[position]);
imageView.setImageBitmap(bm);
return imageView;
}
这里一定要注意语句(1)中为GridView.LayoutParams。否则会报错。
原因:LayoutParams导包时导的是android.view.ViewGroup.LayoutParams包;如果直接用
LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT,screenWidth/4);
则在获取LayoutParams时内部是将这个属性转到android.widget.AbsListView.LayoutParams,也就是这里setLayoutParams弄错了,故这里需要使用GridView.LayoutParam。
基于BaseAdapter的GridView设置ImageView大小的更多相关文章
- UITableview自定义accessory按钮和ImageView大小一致
if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseI ...
- Android UI学习 - GridView和ImageView的使用
GridView: A view that shows items in two-dimensional scrolling grid. The items in the grid come from ...
- 如何使用代码动态的获取和设置ImageView的宽度和高度?
http://blog.csdn.net/wulianghuan/article/details/8644144 国内某金融企业的一道面试题:如何在代码中获得一个ImageVIew的高度和宽度? 相信 ...
- imageView--转-如何代码动态的获取和设置ImageView的宽度和高度?
11- 12- 13-android获取图片原始长宽; ========= 11--国内某金融企业的一道面试题:如何在代码中获得一个ImageVIew的高度和宽度? 相信很大一部分人,会直接想到用im ...
- Android学习笔记:如何设置ImageView中图片的显示方式
我们在用ImageView显示图片时,很多情况下图片的大小与ImageView的尺寸不是完全一样的.这时就涉及到该如何设置显示图片了. ImageView有个重要的属性是ScaleType,该属性用以 ...
- Android - 设置ImageView为全屏显示
设置ImageView为全屏显示 本文地址: http://blog.csdn.net/caroline_wendy ImageView默认会适应屏幕大小, 假设想使用全屏填充, 则须要使用: and ...
- Android 设置ImageView宽度固定,其高度按比例缩放适应
今天和项目经理对喷了一下,他说在应用的列表数据中的图片应该宽度固定,高度按比例缩放自适应,我说,那岂不是很丑!直接让运营那边把图片处理成固定宽高比不就好了,省的我客户端麻烦了. 这家伙不同意,为毛呢, ...
- IDEA设置代码大小以及菜单栏大小
IntelliJ IDEA设置菜单栏大小的方法:File --Settings --Appearance & Behavior -- Appearance ,右边Override defaul ...
- 【转】CSS3的REM设置字体大小
rem 长度单位 在Web中使用什么单位来定义页面的字体大小,至今天为止都还在激烈的争论着,有人说PX做为单位好,有人说EM优点多,还有人在说百分比方便,以至于出现了CSS Font-Size: ...
随机推荐
- 将ubuntu12.04中,gcc4.6/g++4.6版本降低到gcc4.4/g++4.4.
降低Ubuntu中gcc和g++的版本 ubuntu 12.04 中带的gcc/g++都是4.6,将其降到4.4. 操作步骤如下: 一.降低gcc版本 1. $sudo apt-get install ...
- Windows 和 Linux 下 禁止ping的方法
Windows 和Linux 下 禁止ping的方法 目的: 禁止网络上的其他主机或服务器ping自己的服务器 运行环境: Windows 03.08 linux 方法: Windows 03下: ...
- Configuring Report Manager
Steps to configure and get Reports in Report manager. 1. Enable getting Reports in Report Manager. ...
- MongoDB 相关下载
MongoDB 下载:http://www.mongodb.org/ 本实例中MongoDB的C#驱动,支持linq:https://github.com/samus/mongodb-csharp M ...
- [原]Django调试工具--django-debug-toolbar
请摒弃简单粗暴的print --马云 我比较习惯在windows中安装pycharm开发,项目部署在虚拟机中,在本地浏览器中查看效果,这种方式在调试上会有点麻烦,django-debug-toolba ...
- postgresql 分区表
1.普通方式建立主表 create table tbl_partition( id integer, name ), gender boolean, join_date date, dept ) ) ...
- php手册学习
整型:int 转换为整型:intval(str) 32位最大值64位最大值 不存在整除语法:应用round();四舍五入.integer去除小数. $a = 1234; //十进制数 $a = ...
- Delphi的基本函数
Delphi的基本函数 函数由一句或多句代码组成,可以实现某个特定的功能.使用函数可以使代码更加易读.易懂,加快编程速度及减少重复代码.过程与函数类似,过程与函数最重要的区别在于,过程没有返回值,而函 ...
- Python之Redis操作
1.安装驱动 输入命令:pip install redis 2.直接使用驱动 import redis r = redis.StrictRedis(host='127.0.0.1', port=637 ...
- Pycharm 使用 (一)
学习[Python基础教程]到后面的练习阶段就觉得python自带的IDLE有点out的感觉,于是就在网上搜索好用的IDE, 挺多人推荐Pycharm的 不仅跨平台而且还支持django等框架; 初次 ...