【发布时间】:2016-01-06 10:37:12
【问题描述】:
我实现了一个 ViewPager,但我在 instantiateItem 方法中遇到了 OutOfMemory 异常:
@Override
public Object instantiateItem(ViewGroup container, int position) {
Context context = QPhotoGallery.this;
mImageViewForPager = new ImageView(context);
mImageViewForPager.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
mImageForView = mImages.get(position);
File imgFile = new File(mImageForView.getPath());
if (imgFile.exists()) {
mImageViewForPager.setImageURI(Uri.fromFile(imgFile));
if (mImageForView.getOrientation() == ExifInterface.ORIENTATION_ROTATE_90)
mImageViewForPager.setRotation(90);
if (mImageForView.getOrientation() == ExifInterface.ORIENTATION_ROTATE_180)
mImageViewForPager.setRotation(180);
if (mImageForView.getOrientation() == ExifInterface.ORIENTATION_ROTATE_270)
mImageViewForPager.setRotation(270);
}
...
}
这条线:
mImageViewForPager.setImageURI(Uri.fromFile(imgFile));
导致异常。有人有想法吗?
【问题讨论】:
-
图像尺寸问题,请添加适当尺寸的图像或使用高配置设备
-
将图像存储到具有自定义尺寸的新路径并在代码中使用该图像,或使用 Picaso 加载图像。
标签: android android-viewpager out-of-memory android-imageview