And*_*oid 19 android fade image-loading picasso
我想在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 onError() {
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 onError() {
Log.v("Picasso", "Could not fetch image");
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
请帮助我,我已经被困在这很长一段时间了.提前致谢.
ran*_*dom 16
引用杰克沃顿商学院的答案在这里:
如果图像来自除内存缓存之外的任何位置,则应自动应用淡入淡出.
如果你检查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 {
.
.
.
Run Code Online (Sandbox Code Playgroud)
fade effect 已经应用于从n/w而不是内存/缓存加载的图像 FADE_DURATION = 200f; //ms
要强制褪色,再次引用杰克沃顿的答案在这里:
您可以指定noFade(),然后始终在图像加载的回调中播放动画.您还可以依赖同步调用的回调来确定是否需要播放动画.
final AtomicBoolean playAnimation = new AtomicBoolean(true);
Picasso.with(context).load(..).into(imageView, new Callback() {
@Override public void onLoad() {
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);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14202 次 |
| 最近记录: |