我的应用程序使用 url 加载图像。我尝试使用库UrlImageViewHelper。有用。但我想添加一个旋转进度条。所以我尝试修改进度条的一部分。问题是当我尝试运行我的应用程序时,只有在某些图像上才会出现进度条,然后在 iamge 已经加载时消失。在某些图像上,它继续显示..这是添加我的进度条控件的正确位置吗?
final Runnable completion = new Runnable() {
@Override
public void run() {
assert (Looper.myLooper().equals(Looper.getMainLooper()));
Bitmap bitmap = loader.result;
Drawable usableResult = null;
if (bitmap != null) {
usableResult = new ZombieDrawable(url, mResources, bitmap);
}
if (usableResult == null) {
clog("No usable result, defaulting " + url);
usableResult = defaultDrawable;
mLiveCache.put(url, usableResult);
}
mPendingDownloads.remove(url);
// mLiveCache.put(url, usableResult);
if (callback != null && imageView == null)
callback.onLoaded(null, loader.result, url, false);
int waitingCount = 0;
for (final ImageView iv: downloads) {
// validate the url it is waiting for
final String pendingUrl = mPendingViews.get(iv);
if (!url.equals(pendingUrl)) {
clog("Ignoring out of date request to update view for " + url + " " + pendingUrl + " " + iv);
continue;
}
waitingCount++;
mPendingViews.remove(iv);
if (usableResult != null) {
// System.out.println(String.format("imageView: %dx%d, %dx%d", imageView.getMeasuredWidth(), imageView.getMeasuredHeight(), imageView.getWidth(), imageView.getHeight()));
iv.setImageDrawable(usableResult);
// System.out.println(String.format("imageView: %dx%d, %dx%d", imageView.getMeasuredWidth(), imageView.getMeasuredHeight(), imageView.getWidth(), imageView.getHeight()));
// onLoaded is called with the loader's result (not what is actually used). null indicates failure.
}
if (callback != null && iv == imageView)
callback.onLoaded(iv, loader.result, url, false);
}
clog("Populated: " + waitingCount);
// if(imageView.isShown())
// if(progressBar != null) progressBar.setVisibility(View.GONE);
}
};
if (file.exists()) {
try {
if (checkCacheDuration(file, cacheDurationMs)) {
clog("File Cache hit on: " + url + ". " + (System.currentTimeMillis() - file.lastModified()) + "ms old.");
final AsyncTask<Void, Void, Void> fileloader = new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(final Void... params) {
loader.onDownloadComplete(null, null, filename);
return null;
}
@Override
protected void onPostExecute(final Void result) {
completion.run();
}
};
executeTask(fileloader);
return;
}
else {
clog("File cache has expired. Refreshing.");
}
}
catch (final Exception ex) {
}
}
for (UrlDownloader downloader: mDownloaders) {
if (downloader.canDownloadUrl(url)) {
downloader.download(context, url, filename, loader, completion);
return;
}
}
imageView.setImageDrawable(defaultDrawable);
// if(imageView.isShown())
// if(progressBar != null) progressBar.setVisibility(View.GONE);
}
如果有人熟悉这个库,你能帮助实现我的目标吗?谢谢