Picasso and PhotoView Library loads image into ImageView weird

笑着哭i 提交于 2019-12-03 13:04:32

问题


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.

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

The libraries i'm using:

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

回答1:


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

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().

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.




回答2:


I also had the same problem. I solved it by using PhotoView instead of ImageView and removed the PhotoViewAttacher from my code.

In layout file (if you use layout):

<uk.co.senab.photoview.PhotoView
    android:id="@+id/your_photo_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    ... />

And in your code:

PhotoView photoView = (PhotoView) findViewById(R.id.your_photo_view);
Picasso.with(context)
        .load(file)
        ...
        .into(photoView);

Now everything must be correct (at least for me it is!);



来源:https://stackoverflow.com/questions/21749374/picasso-and-photoview-library-loads-image-into-imageview-weird

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!