问题描述
任何想法如何发挥淡入动画时,图像加载?的现在,它只是闪烁到位。我使用NetworkImageView从凌空工具包。
any idea how to play a fade in animation when image loads? Now it just blinks into place. I am using NetworkImageView from the Volley toolkit.
此外,有没有一种方法来设置网络上的图像视图加载和错误的位图,而无需使用ImageLoader.get(..)?
Also, is there a way to set loading and error bitmaps on the network image view without using the ImageLoader.get( .. ) ?
谢谢!
//修改:好了,感谢你的一切,但如果我们想成为完美主义者,我们应该只当负载从磁盘高速缓存,覆盖setImageBitmap将区分动漫走下车动画即使从拉的内存缓存
您想要做的就是添加一个布尔值 shouldAnimate
来ImageListener.onResponse这样
what you want to do is add a boolean shouldAnimate
to ImageListener.onResponse like this
public static ImageListener getImageListener(final ImageView view, final int defaultImageResId,
final int errorImageResId) {
return new ImageListener() {
@Override
public void onErrorResponse(VolleyError error) {
if (errorImageResId != 0) {
view.setImageResource(errorImageResId);
}
}
@Override
public void onResponse(ImageContainer response, boolean isImmediate, boolean shouldAnimate) {
if (response.getBitmap() != null) {
if (shouldAnimate) {
// ADDED
view.setAlpha(0f);
view.setImageBitmap(response.getBitmap());
view.animate().alpha(1f).setDuration(1000);
// END ADDED
} else {
view.setImageBitmap(response.getBitmap());
}
} else if (defaultImageResId != 0) {
view.setImageResource(defaultImageResId);
}
}
};
}
这是一个设置位图,无论是从方法,所以你需要将其设置为false,以在ImageLoader的每次使用时,除了
this is a method that sets the bitmap, no matter where it is from, so you need to set it to false to every usage in ImageLoader except for
class BatchedImageRequest {
private void batchResponse(String cacheKey, BatchedImageRequest request,
final VolleyError error) {
...
container.mListener.onResponse(container, false, true);
...
}
}
我创建了一个要点进行复制和;粘贴的用法 - https://gist.github.com/ursusursus/5732521
推荐答案
例实施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);
这篇关于Android的排球 - 如何动画图像加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!