This is the adapter of my Gallery on which I display ImageViews (thumb of a page)
I want to load the images ASync (some times this can come from Network), so I did that code:
public View getView(int position, View convertView, ViewGroup parent) {
final ImageView image = convertView != null ? convertView : new ImageView(getContext());
final PageInfo page = getItem(position);
image.setBackgroundColor(Color.WHITE);
image.setLayoutParams(new Gallery.LayoutParams(96, 170));
new AsyncTask<Void, Void, Bitmap>() {
@Override
protected Bitmap doInBackground(Void... arg0) {
try {
File thumbnail = page.thumbnail();//Thumbnail download the image if not available
return BitmapFactory.decodeStream(new FileInputStream(thumbnail));
} catch (ApplicationException e) {
return null;
} catch (NetworkException e) {
return null;
}
}
protected void onPostExecute(Bitmap result) {
if (result == null)
return;
image.setImageBitmap(result);
};
}.executeOnExecutor(executor);
return image;
}
This works, but if I'm dragging the Gallery the views (when switching to the real Bitmap) do a "jump" to another position inside the galley, making it weird.
How can I avoid that? Or can I change the image of a ImageView without requesting layout of the ViewGroup?
EDIT: A similar question on Google dev groups http://code.google.com/p/android/issues/detail?id=15526