我认为您想要做的是让DownloadedDrawable
类扩展BitmapDrawable
而不是Drawable
然后选择适当的超级构造函数之一来指定您的默认图像位图:
/**
* A fake Drawable that will be attached to the imageView while the download is in progress.
*
* Contains a reference to the actual download task, so that a download task can be stopped
* if a new binding is required, and makes sure that only the last started download process can
* bind its result, independently of the download finish order.</p>
*/
private static class DownloadedDrawable extends BitmapDrawable {
private final WeakReference<BitmapDownloaderTask>
bitmapDownloaderTaskReference;
private DownloadedDrawable(BitmapDownloaderTask bitmapDownloaderTask,
Resources resources, Bitmap bitmap) {
super(resources, bitmap); // you'll have to provide these
bitmapDownloaderTaskReference =
new WeakReference<BitmapDownloaderTask>(bitmapDownloaderTask);
}
public BitmapDownloaderTask getBitmapDownloaderTask() {
return bitmapDownloaderTaskReference.get();
}
}