毕加索和PhotoView中的库加载图像转换成ImageView的怪异

问题描述:

我加载图像与毕加索库中的ImageView的,然后用PhotoView库添加缩放和平移等的ImageView的。

I'm loading images into an ImageView with the Picasso library and then using the PhotoView Library to add zoom and panning etc.. to the ImageView.

但是,当毕加索加载了图像,第一次显示图片:

But when picasso has loaded the image for the first time it displays the images like this:

但只要我触摸它正确地将影像

But as soon I touch the image it places correctly

但是,如果我结束我的应用程序,它突然再也不和不会显示图像。

But if I close my app it suddenly doesn't show the image anymore and wont.

我的MainActivity: http://pastebin.com/5H4zAgH

My MainActivity: http://pastebin.com/5H4zAgH

我使用的库:

  • http://square.github.io/picasso/
  • https://github.com/chrisbanes/PhotoView

我曾与错位的图像用毕加索的PhotoView在一起的时候同样的问题。

I had the same problem with the misplaced image when using Picasso and Photoview together.

要解决这个问题,我所要做的就是用使用与毕加索加载图像时回调成(视图,回调),而不是仅仅进入(视图)。一旦图像成功加载我实例化PhotoViewAttacher对象或调用方法更新()

To solve it, what I do is to use a callback when loading the image with Picasso using into(view, callback) instead of just into(view). Once the image is loaded successfully I instantiate the PhotoViewAttacher object or call the method update().

在这里,你有code的例子:

Here you have an example of code:

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);

我希望这有助于。问候。

I hope this helps. Regards.