View Pager with Universal Image Loader Out of Memory Error

后端 未结 7 1594
别跟我提以往
别跟我提以往 2021-02-02 01:58

I am not really sure if a ViewPager with Universal Image Loader can/should be used as an alternate for a gallery like interface since I have run into an Out of Memory error whil

7条回答
  •  有刺的猬
    2021-02-02 02:12

    It's probably not the best implementation to solve it, but it worked for me. Removing the ImageViews is not enough, so I decided to recycle bitmaps in 'destroyItem':

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        View view = (View) object;
        ImageView imageView = (ImageView) view.findViewById(R.id.image);
        if (imageView != null) {
            Bitmap bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
            bitmap.recycle();
            bitmap = null;
        }
        ((ViewPager) container).removeView(view);
        view = null;
    }
    

    This does not clean the last 3 active pages when you leave the activity, although I hope that GC takes care of them.

提交回复
热议问题