0

BaseAdapterを使用したギャラリービューがあり、インターネットから画像をダウンロードし、画像をダウンロードして、ギャラリー非同期に設定します。約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を超えると、このプロセスは非常に遅くなります。

任意のアイデア?ありがとう

4

1 に答える 1

0

ImageLoader を見てください。このリンクは、ListViewまたはhttp://androidimageloader.com/での画像の遅延ロードに役立ちます。

また、アクティビティの AndroidManifest で方向の変更を却下することもできます。

android:name="com.example.MainActivity" android:configChanges="keyboardHidden|orientation" android:screenOrientation="portrait"
于 2012-11-06T08:37:23.427 に答える