2014-02-13 60 views
7

我正在加载图像到ImageView与毕加索图书馆,然后使用PhotoView库添加缩放和平移等..到ImageView。毕加索和PhotoView库加载图像到ImageView怪异

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

enter image description here

但是,只要我触摸图像它正确的地方

enter image description here

但是,如果我关闭我的应用程序,它突然不再显示图像,并且不会。

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

我使用的库:

回答

25

我用毕加索,当曾与错位的图像同样的问题Photoview在一起。

为了解决这个问题,我所做的是使用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); 

我希望这有助于。问候。

+0

正是我在找的东西! – dasmikko

+0

如果我每次重新创建联接器而不是更新,它似乎会更好地工作。 –

+0

如果我想使用viewpager怎么办? – randy

19

我也有同样的问题。我通过使用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); 

现在一切都必须是正确的(至少对我来说是!);

+0

为我工作完美:) – Max

+0

谢谢!比回调解决方案更清洁! – Keysersoze

+0

谢谢,这也适用于我:) – Ashwin