First of all, yes, I'm aware of this question, but the answer doesn't help me. Yes, it solves the "changing position when scrolling" issue but it's not a very optimal solution to my problem. Let me explain...
So, this is my getView:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
UnscaledImageView imageView;
if(convertView == null) {
imageView = new UnscaledImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(mIconSize, mIconSize));
imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
imageView.setImageResource(mThumbIds[position]);
} else {
imageView = (UnscaledImageView)convertView;
}
return imageView;
}
And the common solution would be to move imageView.setImageResource(mThumbIds[position]);
outside and below the if
statement. But this creates another problem...
As you may have noticed I'm using a UnscaledImageView
instead of ImageView
. This is a custom subclass of ImageView
where I've overridden the setImageResource()
method to manually decode bitmaps with some extra options to fit my needs. The manual decoding is what causes my problem.
If the setImageResource()
method stays inside the if
, no problem, the bitmap decoding will be done once for bitmap (during GridView loading) and the scrolling will be smooth... But the images will be jumping to different positions with each scroll.
But if the setImageResource()
method stays outside the if
, the images will not jump to different positions but all images will be constantly decoded with each scroll. The scrolling will be jerky and not smooth at all.
How can I solve this issue? Any ideas?