0

I having the "out of memory" error on my ImageAdapter, I tried some solutions reusing the ImageView, but not works, I hope any can help me :)

@Override
public View getView(int position, View convertView, ViewGroup parent) {         
    ImageView imageView;
    if (convertView == null) { 
        imageView = new ImageView(mContext);//Creamos la imagen sólo si no existe
    } else {
        imageView = (ImageView) convertView;//Sino reusamos el objeto
    }

    //Todas con el mismo ancho
    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    imageView.setLayoutParams(new GridView.LayoutParams(70, 70));

    imageView.setImageResource(mThumbIds[position]);
    return imageView;
}

I have some app similar, but not this problem, for sure on this I have 290 diferent images, and the other app I have only one :), I thought that the convertView == null fix the outOfMemory problems

More info: - Only 20 images have more of 100kb, only 3 of these are >500k and <900k

PD: Im using this tutorial code: http://www.androidhive.info/2012/02/android-gridview-layout-tutorial/

Thanks for your help guys and sorry my english

4

1 回答 1

0

Android 程序比大多数程序复杂得多,图像在 Ram 中占用的内存似乎比在磁盘上要多得多。尽管如此,您可以轻松完成一件事,以及其他一些技巧。

  1. 添加android:largeHeap="true"到清单中的应用程序标记。
  2. 运行某种内存分析器来查找泄漏。
  3. 删除任何未使用的变量。
  4. 如果它们在类中一致使用,则使一些变量成为静态变量。
  5. 尝试使用正确大小的图像。

另外,看看如何在内存有限的情况下优雅地降低性能?

于 2012-11-20T18:48:46.133 回答