Picasso library and PhotoView upload image to ImageView weird

I upload images to ImageView with the Picasso library, and then use the PhotoView library to add zooming and panning, etc. in ImageView.

But when picasso uploaded the image for the first time, it displays the following images:

enter image description here

But as soon as I touch the image, it fits correctly

enter image description here

But if I close my application, it suddenly will not show the image and will not.

My main activity: http://pastebin.com/5H4zAgH

Libraries I use:

+7
android image picasso
source share
2 answers

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

To solve this problem, I use a callback when loading an image using Picasso using into(view, callback) instead of into(view) . Once the image is uploaded successfully, I create a PhotoViewAttacher or call the update() method.

Here is a sample 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); 

Hope this helps. Best wishes.

+25
source share

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

In the layout file (if you use the 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 should be correct (at least for me it!);

+19
source share

All Articles