Home » Android » Android ListView asynchronous loading picture disl...

Android ListView asynchronous loading picture dislocation, repeat, blinking problems analysis and solution

1:Item pictures show repeated


this display repeats the current row, and Item displays the picture Item of the previous line.


For example,

ListView sliding to second rows asynchronous loading of a picture, but the slow loading, the loading process of ListView has been sliding into fourteenth lines, the image loading and the sliding process has not ended. Second on the screen, according to the cache principle described above, the second line of the View object may be fourteenth for reuse. So we see that the fourteenth line shows the belonging to the second line of the display picture, caused by repeated.


2. Item pictures show confusion


this display disorder means that a row of Item shows a picture Item that does not belong to the row.


is the same as above,.


3. Item pictures show flashing


Another

described above, if the fourteenth line pictures quickly loaded end, so we see the fourteenth line shows the first multiplexed second rows of images immediately and show their pictures covering.

causing flicker.



/**
* show this picture and solve the list problem
* list problem: during the slide, the imageView of getView is reused, causing the pictures to be strung together
* @param imageView appears to be View
* @param, URL, the, URL
* @return
* /
Public, void, display (final, ImageView, imageView, String, URL) {
If (AbStrUtil.isEmpty (URL)) {
If (noImage = = null) {
If (loadingView = = null) {
LoadingView.setVisibility (View.INVISIBLE);
ImageView.setVisibility (View.VISIBLE);
}
ImageView.setImageDrawable (noImage);
}
Return;
}
Set / download
Final, AbImageDownloadItem, item = new, AbImageDownloadItem ();
/ / set the display size
Item.width = width;
Item.height = height;
/ / set to zoom
Item.type = type;
Item.imageUrl = url;
Final, String, cacheKey = AbImageCache
.getCacheKey (item.imageUrl, item.width, item.height, item.type);
Item.bitmap = AbImageCache.getBitmapFromCache (cacheKey);
//if (D) Log.d (TAG, "+cacheKey+", "" obtained in the cache "+item.bitmap");
Set / mark
ImageView.setTag (URL);
If (item.bitmap = = null) {
Show / / the first loading
If (loadingView = = null) {
LoadingView.setVisibility (View.VISIBLE);
ImageView.setVisibility (View.INVISIBLE);
} else if (loadingImage = = null) {
ImageView.setImageDrawable (loadingImage);
}
Download the update / interface is finished
Item.setListener (new, AbImageDownloadListener () {
@Override
Public, void, update (Bitmap, bitmap, String, imageUrl) {
The picture is not loaded / / set, and set up a hidden View
If (loadingView! = null & & imageUrl.equals ((imageView.getTag))) {
LoadingView.setVisibility (View.INVISIBLE);
ImageView.setVisibility (View.VISIBLE);
}
To determine the imageView / / url change, if there is no change to set,
There are changes / cancellations, solve the problem of repeated use of the View list
If (bitmap, =null&&, imageUrl.equals (imageView.getTag ())) {
If (D) Log.d (TAG, picture download, settings: +imageUrl);
ImageView.setImageBitmap (bitmap);
} else {
If (errorImage! = null & & imageUrl.equals ((imageView.getTag))) {
ImageView.setImageDrawable (errorImage);
}
}
}
});
If (D) Log.d (TAG, picture download, execute: +url);
MAbImageDownloadPool.execute (item);
} else {
If (loadingView = = null) {
LoadingView.setVisibility (View.INVISIBLE);
ImageView.setVisibility (View.VISIBLE);
}
ImageView.setImageBitmap (item.bitmap);
}
}








Latest