关于Gallery的问题? 当滑动的中间的时候,有点卡,所以我用了个异步加载,可以异步加载的时候,有一张大点的图片出现了内存泄漏的问题。没加异步的时候,没有这样的问题,这是为什么呢?是不是异步加载写错了。异步加载该怎么写?真正的无限循环能不能实现?而不是把getCount()里面把值设成无限大 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我的异步加载实在adapter中写的,是不是有问题?public class GalleryAdapter extends BaseAdapter { private ImageView[] imageView;// 加载图片的imageView数组 private Context context; private Integer[] imagesId;// 要显示的图片 public GalleryAdapter(Context context) { this.context = context; imagesId = new Integer[] { R.drawable.a, R.drawable.b, R.drawable.c, R.drawable.d }; imageView = new ImageView[imagesId.length]; } // 返回要显示的图片的总数 public int getCount() { return imagesId.length; } // 获得相关的数据项中的指定位置的数据集。这里我们可以指定为该位置的Bitmap public Object getItem(int position) { Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), imagesId[position]); return bitmap; } // 返回相关位置的item的id,这里返回和position一样的ID public long getItemId(int position) { return position; } public View getView(int position, View convertView, ViewGroup parent) { if (imageView[position] == null) imageView[position] = new ImageView(context); new MyTask().execute(position); return imageView[position]; } private class MyTask extends AsyncTask<Integer, Void, Void> { private Bitmap bitmap; private int position; @Override protected Void doInBackground(Integer... params) { // position = params[0]; // BitmapFactory.Options options = new BitmapFactory.Options(); // options.inSampleSize = 2 ; bitmap = BitmapFactory.decodeResource(context.getResources(), imagesId[params[0]]); return null; } @Override protected void onPostExecute(Void result) { super.onPostExecute(result); imageView[position].setImageBitmap(bitmap); } }} 如何绑定ViewPager中各页面中的元素? 关于前置摄像头的问题 用HTML5 开发android时JS跳转无效 游戏开发怪物怎么移动的 问一个比较弱智的问题 利用传感器求位移 如何在fragment中使用百度地图?? phonegap 打包签名后,不能通过phonegap调用api应该是打包混淆文件后出问题 安卓获取所有应用信息为什么获取不到相机? 求助,Android JNI 线程中回调JAVA,在此回调函数中startActivity未报错,但起不来 一个不好解的内存问题 怎把java代码变成android代码
public class GalleryAdapter extends BaseAdapter {
private ImageView[] imageView;// 加载图片的imageView数组
private Context context;
private Integer[] imagesId;// 要显示的图片 public GalleryAdapter(Context context) {
this.context = context;
imagesId = new Integer[] { R.drawable.a, R.drawable.b, R.drawable.c, R.drawable.d };
imageView = new ImageView[imagesId.length];
} // 返回要显示的图片的总数
public int getCount() {
return imagesId.length;
} // 获得相关的数据项中的指定位置的数据集。这里我们可以指定为该位置的Bitmap
public Object getItem(int position) {
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), imagesId[position]);
return bitmap;
} // 返回相关位置的item的id,这里返回和position一样的ID
public long getItemId(int position) {
return position;
} public View getView(int position, View convertView, ViewGroup parent) {
if (imageView[position] == null)
imageView[position] = new ImageView(context);
new MyTask().execute(position);
return imageView[position];
} private class MyTask extends AsyncTask<Integer, Void, Void> {
private Bitmap bitmap;
private int position; @Override
protected Void doInBackground(Integer... params) {
// position = params[0];
// BitmapFactory.Options options = new BitmapFactory.Options();
// options.inSampleSize = 2 ;
bitmap = BitmapFactory.decodeResource(context.getResources(), imagesId[params[0]]);
return null;
} @Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
imageView[position].setImageBitmap(bitmap);
}
}
}