且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Android Volley - 如何动画图像加载?

更新时间:2023-02-01 16:06:50

CommonsWare 答案的示例实现可以在这里找到:https://gist.github.com/benvd/5683818.

Example implementation of CommonsWare's answer can be found here: https://gist.github.com/benvd/5683818.

使用 TransitionDrawable 确实增加了一层额外的过度绘制.如果您想避免这种情况,也许使用 ViewPropertyAnimator 可能会有所帮助.

Using a TransitionDrawable does add an extra layer of overdraw. If you want to avoid that, perhaps using a ViewPropertyAnimator might help.

它的要点基本上是在您的 setImageBitmap() 中有以下代码段:

The gist of it is basically to have the following snippet in your setImageBitmap():

TransitionDrawable td = new TransitionDrawable(new Drawable[]{
        new ColorDrawable(android.R.color.transparent),
        new BitmapDrawable(getContext().getResources(), bm)
});

setImageDrawable(td);
td.startTransition(FADE_IN_TIME_MS);