大佬教程收集整理的这篇文章主要介绍了Android ViewPager内存泄漏,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
private static final int[] images = {R.drawable.tutorial_step_01,R.drawable.tutorial_step_02,R.drawable.tutorial_step_03,R.drawable.tutorial_step_04,R.drawable.tutorial_step_05,R.drawable.tutorial_step_06};
然后我创建适配器:
@Override public Object instantiateItem(ViewGroup container,int position) { LinearLayout tv = (LinearLayout) inflater.inflate(R.layout.tut_slide,null); TextView title = (TextView) tv.findViewById(R.id.tut_titlE); title.setText(getresources().getText(titles[position])); TextView content = (TextView) tv.findViewById(R.id.tut_content); ImageView image = (ImageView) tv.findViewById(R.id.tut_imagE); slide_image = BitmapFactory.decoderesource(getresources(),images[position]); image.setImageBitmap(slide_imagE); content.setText(getresources().getText(contents[position])); ((ViewPager) container).addView(tv,0); return tv; } @Override public void destroyItem(ViewGroup container,int position,Object object) { ((ViewPager) container).removeView((LinearLayout) object);
麻烦的是,在我选择另一个页面之后,android不想收集图像.因此,在10-15次更改后,它会出现OutOfMemory异常.然后我添加到initializung行
if (slide_image!= null) { slide_image.recycle(); System.gc(); }
它工作得很好!但除了一件事:我有黑色屏幕而不是第一张图像,在几次翻转之后被真正的图像取代.所以我不知道如何处理这种内存泄漏
以上是大佬教程为你收集整理的Android ViewPager内存泄漏全部内容,希望文章能够帮你解决Android ViewPager内存泄漏所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。