2011-02-17 44 views
1

在图库的getView方法中, 我已下载位图并设置为Imageview并将其返回给框架。 何时何地应该回收位图? 我不想唤醒系统垃圾回收器来清理位图。如何从Android Gallery回收位图:: GetView方法

public View getView(int position, View view, ViewGroup parent) { 
     ImageView i = new ImageView(mContext); 
     downloadFromWeb("www.blahblah.com", i); 
     i.setScaleType(ImageView.ScaleType.FIT_XY); 
     i.setLayoutParams(new Gallery.LayoutParams(mDisplayWidth, (mDisplayHeight-100))); 
     i.setBackgroundResource(mGalleryItemBackground); 
     return i; 
    } 

public downloadFromWeb(URL url, ImageView i){ 
     Bitmap bitmap = getBitmapFromWeb(url); 
     i.setImageBitmap(bitmap); 
    } 
+0

为了获得名声,并让别人来回答你的问题,投票,并接受您的问题 – 2011-02-21 18:45:47

回答

0
You can call bitmap recycle method in onDestory method as shown below 

Bitmap mybitmap= null; 

@Override 
    protected void onDestroy() { 
     super.onDestroy(); 

     if(bm!=null) 
     mybitmap.recycle(); 

    } 
+1

如果你持有的位图的引用的工作很好的答案。当你把它交给观点时呢?它是否自己做到这一点?或者我必须保持对放置在画廊中的位图的控制,并确保在完成画廊时释放它们。 – 2011-04-15 22:27:03

相关问题