imageswitcher的内存问题

时间:2011-11-30 05:51:38

标签: android android-imageview android-file

我正在尝试从SDCard中的文件夹中将一些图像加载到我的ImageSwitcher上。我正在创建一个runnable并在循环中执行,以便一个接一个地显示图像。

 final ImageSwitcher imageSwitcher = (ImageSwitcher) findViewById(R.id.imageSwitcher1);
             imageSwitcher.postDelayed(
                     new Runnable() {

                         @Override
                         public void run() {
                             i++;

                             File dir = new File("/sdcard/Wallpapers/My Wallpapers");
                             final File file[]=dir.listFiles();

                                 imageSwitcher.setImageURI(Uri.fromFile(file[i]));
                                 imageSwitcher.postDelayed(this, 2000); 


                         }
                     },
                     2000);

有些图片工作正常,过了一段时间,应用因“outofmemory”异常而崩溃。

我尝试通过将此代码放在:

下面来解决内存问题
  

“imageSwitcher.postDelayed(this,2000);”

这是我放在那里的代码:

ImageView v = (ImageView)imageSwitcher.getNextView(); 
BitmapDrawable bd = (BitmapDrawable) v.getDrawable(); 
Bitmap b = bd.getBitmap();
b.recycle();

此强制使用Nullpointer异常关闭应用程序。

我想知道如何处理这个内存问题..或者我哪里出错?

0 个答案:

没有答案
相关问题