回收ImageViews以避免OutOfMemoryError [英] Recycle ImageViews to avoid OutOfMemoryError
问题描述
在某些手机(特别是三星)中,应用程序会出现OutOfMemory错误。
In some phones (especially Samsungs), the application gives an error of OutOfMemory.
我使用带有4个ImageView的ViewFlipper,它们会在教程中显示。
I use a ViewFlipper with 4 ImageViews which they are shown in a tutorial.
我发现无法解决错误或回收图像视图。
I have found no way to remedy the error or recycle imageviews.
这是管理ViewFlipper的方法:
This is the method that manages the ViewFlipper:
private void changeBackground(int position) {
switch (position) {
case 1:
mViewFlipper.setDisplayedChild(1);
mViewFlipper.setInAnimation(getActivity(), R.anim.anim_clockwise_onboarding);
mViewFlipper.setOutAnimation(getActivity(), R.anim.anim_clockwise_inverse_onboarding);
break;
case 2:
mViewFlipper.setDisplayedChild(2);
mViewFlipper.setInAnimation(getActivity(), R.anim.anim_clockwise_onboarding);
mViewFlipper.setOutAnimation(getActivity(), R.anim.anim_clockwise_inverse_onboarding);
break;
case 3:
mViewFlipper.setDisplayedChild(3);
mViewFlipper.setInAnimation(getActivity(), R.anim.anim_clockwise_onboarding);
mViewFlipper.setOutAnimation(getActivity(), R.anim.anim_clockwise_inverse_onboarding);
break;
default:
mViewFlipper.setDisplayedChild(0);
mViewFlipper.setInAnimation(getActivity(), R.anim.anim_clockwise_onboarding);
mViewFlipper.setOutAnimation(getActivity(), R.anim.anim_clockwise_inverse_onboarding);
break;
}
}
方法是每次在ViewPager中更改页面时都会调用。
The method is called each time you change pages in a ViewPager.
@Override
public void onPageSelected(int position) {
changeBackground(mViewPager.getCurrentItem());
}
如果有任何想法请帮助我,提前致谢。
If any have idea please help me, Thanks in advance.
推荐答案
为此你需要使用Image loader库来加载图像。
您可以使用:
For that you need to use Image loader library for loading images. You can use :
- 通用图片加载器
- Picasso
- Glide
此库用于位图内存管理,使用此库后,您没有遇到OutOfMemoryError异常。
This library uses for bitmap memory management and after using this library you didn't face OutOfMemoryError exeption.
这篇关于回收ImageViews以避免OutOfMemoryError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!