Java 带有附加变量的AsyncTask的动画占位符图像

Java 带有附加变量的AsyncTask的动画占位符图像,java,android,android-asynctask,android-recyclerview,Java,Android,Android Asynctask,Android Recyclerview,我正在使用来自的代码将图像异步加载到RecyclerView中。我现在的问题是,我想在加载动画时显示动画。不幸的是,AnimatedVectorDrawable和AnimatedVectorDrawableCompat不能像在文章中那样进行扩展,因为所有构造函数都是私有的。我也没有选择,因为它不支持动画海报还有其他干净的方法吗?我希望答案中有几行不需要外部依赖的代码。 编辑: 我现在将此类作为占位符: static class DownloadedDrawable extends ColorDr

我正在使用来自的代码将图像异步加载到RecyclerView中。我现在的问题是,我想在加载动画时显示动画。不幸的是,AnimatedVectorDrawable和AnimatedVectorDrawableCompat不能像在文章中那样进行扩展,因为所有构造函数都是私有的。我也没有选择,因为它不支持动画海报
还有其他干净的方法吗?我希望答案中有几行不需要外部依赖的代码。

编辑:

我现在将此类作为占位符:

static class DownloadedDrawable extends ColorDrawable
{
    private final WeakReference<BitmapDownloaderTask> bitmapDownloaderTaskReference;

    public DownloadedDrawable(BitmapDownloaderTask bitmapDownloaderTask)
    {
        super(Color.TRANSPARENT);
        bitmapDownloaderTaskReference = new WeakReference<>(bitmapDownloaderTask);
    }

    public BitmapDownloaderTask getBitmapDownloaderTask()
    {
        return bitmapDownloaderTaskReference.get();
    }
}
我想要得到的是一个功能与此相同的东西(如果它起作用的话),我可以像现在使用的占位符一样使用它:

static class AnimatedDownloadedDrawable extends AnimatedVectorDrawable
{
    private final WeakReference<BitmapDownloaderTask> bitmapDownloaderTaskReference;

    public AnimatedDownloadedDrawable(BitmapDownloaderTask bitmapDownloaderTask)
    {
        super(R.drawable.myAnimation);
        bitmapDownloaderTaskReference = new WeakReference<>(bitmapDownloaderTask);
    }

    public BitmapDownloaderTask getBitmapDownloaderTask()
    {
        return bitmapDownloaderTaskReference.get();
    }
}
静态类AnimatedDownloadedDrawable扩展AnimatedVectorDrawable
{
私有最终WeakReference位图下载程序taskreference;
公共动画下载可绘制(位图下载任务位图下载任务)
{
超级(R.drawable.myAnimation);
bitmapDownloaderTaskReference=新的WeakReference(bitmapDownloaderTask);
}
公共BitmapDownloaderTask getBitmapDownloaderTask()
{
返回bitmapDownloaderTaskReference.get();
}
}

制作动画占位符的问题到底是什么?这样做不需要任何库,也不需要扩展
VectorDrawable
类来创建动画向量drawable。您只需要用xml定义可绘制和动画,我已经做了,动画本身也在工作。他们正在使用一个自定义类,该类保存对创建它的BitmapDownloaderTask的引用。这就是我被困的地方。我无法创建一个类来扩展一个可设置动画的Drawable来保存对任务的额外引用。
static class AnimatedDownloadedDrawable extends AnimatedVectorDrawable
{
    private final WeakReference<BitmapDownloaderTask> bitmapDownloaderTaskReference;

    public AnimatedDownloadedDrawable(BitmapDownloaderTask bitmapDownloaderTask)
    {
        super(R.drawable.myAnimation);
        bitmapDownloaderTaskReference = new WeakReference<>(bitmapDownloaderTask);
    }

    public BitmapDownloaderTask getBitmapDownloaderTask()
    {
        return bitmapDownloaderTaskReference.get();
    }
}