我有一个带有 BaseAdapter 的画廊视图,我从 Internet 下载图像,下载图像并设置为画廊异步。大约有2000张图片。当我旋转屏幕时,异步任务继续,但画廊设置为空并且不显示任何现在或旧图像。
这是 BaseAdapter 的代码:
private class AdaptadorImagenes extends BaseAdapter {
private Context contexto = null;
private ArrayList<Integer> datos = new ArrayList<Integer>();
public AdaptadorImagenes(Context contexto) {
this.contexto = contexto;
}
public void addItem(Integer posicion) {
datos.add(posicion);
notifyDataSetChanged();
}
@Override
public int getCount() {
return datos.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imagen = new ImageView(contexto);
imagen.setImageBitmap(getBitMapRedimensionado(position));
imagen.setScaleType(ScaleType.FIT_XY);
return imagen;
}
/**
* Metodo para redimensionar un bimap
*
* @param posicion
* del bitmap en una lista que contiene los path
* @return bitmap redimensionado
*/
private Bitmap getBitMapRedimensionado(int posicion) {
File fichero = new File(pathImagenes.get(posicion));
Bitmap bmOriginal = redondeaEsquinasBitmap(Bitmap
.createScaledBitmap(
BitmapFactory.decodeFile(fichero.toString()), 210,
210, true));
return bmOriginal;
}
/**
* Metodo para redondear las esquinas de un bitmap
*
* @param bitmap
* a redondear
* @return bitmap redondeado
*/
public Bitmap redondeaEsquinasBitmap(Bitmap bitmap) {
Bitmap salida = Bitmap.createBitmap(bitmap.getWidth(),
bitmap.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(salida);
final int color = 0xff424242;
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bitmap.getWidth(),
bitmap.getHeight());
final RectF rectF = new RectF(rect);
final float roundPx = 12;
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return salida;
}
}
在我设置的清单中 android:configChanges="keyboardHidden|orientation"
我认为将已下载的图像数量保存在一个变量中,并在旋转屏幕时设置所有图像,但是当超过 500 个时,此过程非常缓慢。
有什么想法吗?谢谢