我正在使用 Picasso 库将图像加载到 ImageView 中,然后使用 PhotoView 库将缩放和平移等添加到 ImageView。
但是,当毕加索第一次加载图像时,它会显示如下图像:
但是一旦我触摸它正确放置的图像
但是,如果我关闭我的应用程序,它会突然不再显示图像并且不会。
我的主要活动:http: //pastebin.com/5H4zAgH
我正在使用的库:
我正在使用 Picasso 库将图像加载到 ImageView 中,然后使用 PhotoView 库将缩放和平移等添加到 ImageView。
但是,当毕加索第一次加载图像时,它会显示如下图像:
但是一旦我触摸它正确放置的图像
但是,如果我关闭我的应用程序,它会突然不再显示图像并且不会。
我的主要活动:http: //pastebin.com/5H4zAgH
我正在使用的库:
一起使用 Picasso 和 Photoview 时,我对放错位置的图像有同样的问题。
为了解决这个问题,我所做的是在使用 Picasso 加载图像时使用回调,into(view, callback)
而不是使用into(view)
. 成功加载图像后,我将实例化 PhotoViewAttacher 对象或调用方法update()
。
这里有一个代码示例:
Callback imageLoadedCallback = new Callback() {
@Override
public void onSuccess() {
if(mAttacher!=null){
mAttacher.update();
}else{
mAttacher = new PhotoViewAttacher(mImageView);
}
}
@Override
public void onError() {
// TODO Auto-generated method stub
}
};
Picasso.with(mContext)
.load(mImageUrl)
.into(mImageView,imageLoadedCallback);
我希望这有帮助。问候。
我也有同样的问题。我通过使用PhotoView
而不是解决了它,ImageView
并PhotoViewAttacher
从我的代码中删除了。
在布局文件中(如果您使用布局):
<uk.co.senab.photoview.PhotoView
android:id="@+id/your_photo_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
... />
在您的代码中:
PhotoView photoView = (PhotoView) findViewById(R.id.your_photo_view);
Picasso.with(context)
.load(file)
...
.into(photoView);
现在一切都必须正确(至少对我来说是正确的!);