Dun*_*gan 7 android android-animation picasso android-transitions
我正在尝试将URL中的图像加载到ImageView使用Picasso中.
共享转换的图像位于a CardView中RecyclerView,而第二个图像位于LinearLayout中.第一次发出请求时,元素没有动画,因为毕加索需要将图像加载到视图中,但是在后续请求中它很好.
如何ImageView在启动转换之前确保已成功填充?
Dun*_*gan 26
解决方案是使用postponeEnterTransition()和startPostponedEnterTransition()调用以确保毕加索在活动开始之前已将图像加载到视图中.
这是一篇很棒的博客文章.
以下是您可能使用的示例 onCreate
ActivityCompat.postponeEnterTransition(this);
Picasso.with(this.getApplicationContext())
.load("https://goo.gl/oiyTor")
.noFade()
.fit()
.centerInside()
.error(R.drawable.user_placeholder_error)
.into(((ImageView) findViewById(R.id.game_view_image)), new Callback() {
@Override
public void onSuccess() {
ActivityCompat.startPostponedEnterTransition(targetActivity);
}
@Override
public void onError() {
ActivityCompat.startPostponedEnterTransition(targetActivity);
}
});
Run Code Online (Sandbox Code Playgroud)
如果您想避免因推迟输入转换而导致的影响,您可以强制Picasso使用缓存中已有的任何内容:
Target target = new Target() {
@Override public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
this.imageView.setImageBitmap(bitmap);
}
@Override public void onBitmapFailed(Drawable errorDrawable) {}
@Override public void onPrepareLoad(Drawable placeHolderDrawable) {}
};
Picasso.with(context)
.load(url)
.networkPolicy(NetworkPolicy.OFFLINE)
.into(target);
Run Code Online (Sandbox Code Playgroud)
通过传递Target实例而不是你的实例ImageView,你将迫使Picasso提供它为该URL缓存的任何内容.如果您通过了ImageView,则不会立即加载图像.
请注意,您应该将目标对象保存在成员变量中,因为它被Picasso保存为弱引用,因此您不希望它被垃圾回收.
| 归档时间: |
|
| 查看次数: |
4784 次 |
| 最近记录: |