2014-02-13 25 views
1

由于Bitmap,我已经阅读了大量关于android内存不足的内容,并采取了各种措施来防止它,但它不断敲门。这里是我的代码:位图(列表视图)的OutOfMemoryError

CODE:

in = httpConn.getInputStream(); 
    BitmapFactory.Options options = new BitmapFactory.Options(); 
    options.inPurgeable=true; 
    options.inJustDecodeBounds = true; 
    options.inSampleSize = 1; 
    options.inJustDecodeBounds = false; 
    image = BitmapFactory.decodeStream(in, null, options); 

我能够装载大约15的图像,是具有尺寸640 * 640。之后,它在日志猫中抛出了一个OutOfMemoryError。我还为“PullToRefresh”功能实施了外部库(从GitHub)。很显然,这涉及到自定义列表视图。有什么办法可以避免这个内存问题。

注意:我已经阅读this。我也实施了这些方法,但它仍然没有站起来。

我可以使用列表视图的片段以避免此内存问题吗?或者,我错过了什么?任何帮助将非常感激。提前致谢。

回答

0

只要改变options.inSampleSize = 1;options.inSampleSize = 4;

又办

bitmap.reCycle(); 
+0

设置inSampleSize 4降低我的图像尺寸!将尝试bitmap.recycle()并返回到亚。 – San

+0

将样品更换为2,并查看图片 – Ameer

+0

这让我体面大小,但将其设置为1,这符合我的期望。我也很清楚inSampleSize应该总是设置为2的幂。 – San

0

好了,现在图像加载时间从互联网上有很多解决方案。你也可以使用这个库“Android-Query”https://code.google.com/p/android-query/wiki/ImageLoading。它会给你所需的所有activity.Make确定你想要做什么?并阅读图书馆维基页面。并解决图片加载限制。

这是我的代码: -

@Override 
public View getView(int position, View convertView, ViewGroup parent) { 
    View v = convertView; 
    if (v == null) { 
     LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     v = vi.inflate(R.layout.row, null); 
    } 

    ImageView imageview = (ImageView) v.findViewById(R.id.icon); 
      AQuery aq = new AQuery(convertView); 

      String imageUrl = "http://www.vikispot.com/z/images/vikispot/android-w.png"; 

      aq.id(imageview).progress(this).image(imageUrl, true, true, 0, 0, new BitmapAjaxCallback(){ 

        @Override 
        public void callback(String url, ImageView iv, Bitmap bm, AjaxStatus status){ 

         iv.setImageBitmap(bm); 


        } 

      }); 

    } 
    return v; 
}