0

I have a long list of icons (about 30) in my layout, so I am getting an OutOfMemory error in Android 2.3.3.

What I want to do is creating Drawable object if only necessary (icon is visible on the current scroll).

But how to now if imageview is on the screen or not? I couldn't find a listener for this.

My icons (png files) are already in drawables folder. There is no downloading process at all.

previous_developer
  • 10,579
  • 6
  • 41
  • 66

2 Answers2

1

Try to use ImageLoader Library which provide you lots of custom option to load list with Images...enter link description here

Swap-IOS-Android
  • 4,363
  • 6
  • 49
  • 77
0

This is how I solved my problem;

Bitmap image = BitmapFactory.decodeResource(getResources(), R.drawable.icon1);
Bitmap loBitmap = Bitmap.createScaledBitmap(image, iconSize , iconSize, true);
imageView.setImageBitmap(loBitmap);

iconSize was already calculated in my case.

I didn't want to use an external library for such simple task, so I give up with lazy loading and just get rid of OOM exception.

Because of my question is about listening for view entering the screen event, I will mark @Swap-IOS-Android's answer as the answer. You can check out the library source to see how it works.

previous_developer
  • 10,579
  • 6
  • 41
  • 66