android– 加载图像时淡入动画使用Picasso

android– 加载图像时淡入动画使用Picasso,第1张

概述我想在Imageview上加载图像时显示淡入淡出效果.我正在使用毕加索来缓存图像并在图像视图中显示.我已经搜索了很多,但无法找到任何解决方案.我之前使用过,我知道在某些版本中他们有.fade(intDuration)方法在加载时淡化图像,但我再也找不到这种方法了.这就是我现在正在做的事情P

我想在ImagevIEw上加载图像时显示淡入淡出效果.我正在使用毕加索来缓存图像并在图像视图中显示.我已经搜索了很多,但无法找到任何解决方案.

我之前使用过,我知道在某些版本中他们有.fade(int Duration)方法在加载时淡化图像,但我再也找不到这种方法了.

这就是我现在正在做的事情

Picasso.with(context)                .load(vIEwHolder.data.imageList.get(0).url)                .networkPolicy(NetworkPolicy.OFFliNE)                .placeholder(R.drawable.a_place_holder_List_vIEw)                .error(R.drawable.a_place_holder_List_vIEw)                .into(vIEwHolder.ivUser, context.loadImage(vIEwHolder.ivUser, vIEwHolder.data.imageList.get(0).url));public Callback loadImage(RoundedImageVIEw ivUser, String url) {    return new callback(ivUser, url);}public class callback implements Callback {    RoundedImageVIEw imageVIEw;    String url;    public callback(RoundedImageVIEw imageVIEw, String url) {        this.imageVIEw = imageVIEw;        this.url = url;    }    @OverrIDe    public voID onSuccess() {    }    @OverrIDe    public voID one rror() {        Picasso.with(BaseActivity.this)                .load(url)                .placeholder(R.drawable.a_place_holder_List_vIEw)                .error(R.drawable.a_place_holder_List_vIEw)                .into(imageVIEw, new Callback() {                    @OverrIDe                    public voID onSuccess() {                    }                    @OverrIDe                    public voID one rror() {                        Log.v("Picasso", "Could not fetch image");                    }                });    }}

请帮助我,我已经被困在这很长一段时间了.
提前致谢.

解决方法:

引用杰克沃顿的回答here:

If the image comes from anywhere except the memory cache the fade
should be automatically applIEd.

如果你检查PicassoDrawable

boolean fade = loadedFrom != MEMORY && !noFade;if (fade) {  this.placeholder = placeholder;  animating = true;  startTimeMillis = SystemClock.uptimeMillis();}...@OverrIDe public voID draw(Canvas canvas) {if (!animating) {  super.draw(canvas);} else {...

淡入淡出效果已经应用于从n / w而不是内存/缓存加载的图像
和FADE_DURATION = 200f; //女士

为了强制淡出,再次引用杰克沃顿的回答here:

You can specify noFade() and then always play an animation in the
image loaded callback. You can also rely on the callback being called
synchronously to determine if an animation needs played.

final AtomicBoolean playAnimation = new AtomicBoolean(true);Picasso.with(context).load(..).into(imageVIEw, new Callback() {  @OverrIDe public voID onl oad() {    if (playAnimation.get()) {      //play fade      Animation fadeOut = new AlphaAnimation(0, 1);      fadeOut.setInterpolator(new AccelerateInterpolator());      fadeOut.setDuration(1000);      imageVIEw.startAnimation(fadeOut);      Animation fadeOutPlaceholder = new AlphaAnimation(1, 0);      fadeOutPlaceholder.setInterpolator(new AccelerateInterpolator());      fadeOutPlaceholder.setDuration(1000);      placeHolderImageVIEw.startAnimation(fadeOutPlaceholder);    }  }  //..});playAnimation.set(false);
总结

以上是内存溢出为你收集整理的android – 加载图像时淡入动画使用Picasso全部内容,希望文章能够帮你解决android – 加载图像时淡入动画使用Picasso所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1096799.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存