我有ViewPager和FragmentPagerAdapter,我希望显示大量高质量的图像。我有自定义FragmentPagerAdapter,我把它放入数组路径,然后我为每个图像创建片段。问题在于,当我有很多图像时,在ViewPager项目之间滚动变得太慢。有什么方法可以快速滚动?
答案 0 :(得分:2)
您可以使用PagerAdapter
覆盖destroyItem
,它适用于大型图片:
private class ImagePagerAdapter extends PagerAdapter{
@Override
public int getCount() {
return mPhotos.size();
}
@Override
public boolean isViewFromObject(View view, Object obj) {
return obj.equals(view);
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
((ViewPager)container).removeView((View)object);
}
@Override
public Object instantiateItem(ViewGroup view, int position) {
View imageLayout = getLayoutInflater().inflate(R.layout.item_pager_image, view, false);
ImageView imageView = (ImageView) imageLayout.findViewById(R.id.image);
// set up imageView
view.addView(imageLayout, 0);
return imageLayout;
}
}