滚动网格视图时点击 OutOfMemoryError。
适配器代码:
package com.example.gridviewexample;
import android.content.*;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
public class ImageAdapter extends BaseAdapter {
private Context mContext;
private Integer arrayElement[] = {
R.drawable.rkt, R.drawable.images,R.drawable.sir,R.drawable.sir2,
R.drawable.sir3,R.drawable.sir4, R.drawable.images1,
R.drawable.images3, R.drawable.indeerx,
R.drawable.index,R.drawable.rkt2,R.drawable.rkt3,R.drawable.rkt4,R.drawable.rkt5,R.drawable.sir2,
R.drawable.sir3,
};
public ImageAdapter(Context c){
mContext = c;
}
@Override
public int getCount() {
return arrayElement.length;
}
@Override
public Integer getItem(int position) {
return arrayElement[position];
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView = new ImageView(mContext);
imageView.setImageResource(arrayElement[position]);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setLayoutParams(new GridView.LayoutParams(200,200));
return imageView;
}
}
任何建议将不胜感激!