如何从 android Gallery::GetView 方法回收位图
在 gallery 的 getView 方法中, 我已经下载了位图并设置为 Imageview 并将其返回到框架。 我应该何时何地回收位图? 我不想唤醒系统垃圾收集器来清理位图。
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);
}
In getView method of gallery ,
i had download the bitmap and set to Imageview and return it back to framework.
When and where should i recycle the bitmap ?
I don't want to wake up the system garbage collector to clean up the bitmaps.
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);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)