0
picassoライブラリとphotoviewライブラリでviewpagerを使用しているときに直面している2つの問題があります。viewpager + picasso + photoview issue
1)一部の画像はズームされませんが、次の画像がズームされることがあります。
2)画像をズームすると、隣接する画像も現在のズームと一緒にズームされることがあります。
上記の2つの問題を解決するにはどうすればよいですか?
public class ImageViewerPagerAdapter extends PagerAdapter implements PhotoViewAttacher.OnViewTapListener {
Context context;
private int count;
private ArrayList<String> images;
private PhotoViewAttacher mAttacher;
private boolean shouldFit = false;
public ImageViewerPagerAdapter(Context context, int count, ArrayList<String> images, boolean shouldFit) {
this.context = context;
this.count = count;
this.images = new ArrayList<>(images);
this.shouldFit = shouldFit;
}
@Override
public int getCount() {
return count;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((FrameLayout) object);
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
String imageUrl = images.get(position);
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.activity_image_viewpager_layout, container, false);
final PhotoView imageView = (PhotoView) view.findViewById(R.id.image);
if (shouldFit) {
Picasso.with(context).load(imageUrl).into(imageView, new Callback() {
@Override
public void onSuccess() {
if (mAttacher != null) {
mAttacher.update();
} else {
mAttacher = new PhotoViewAttacher(imageView);
mAttacher.setOnViewTapListener(ImageViewerPagerAdapter.this);
}
}
@Override
public void onError() {
}
});
} else {
Picasso.with(context).load(imageUrl).into(imageView, new Callback() {
@Override
public void onSuccess() {
if (mAttacher != null) {
mAttacher.update();
} else {
mAttacher = new PhotoViewAttacher(imageView);
mAttacher.setOnViewTapListener(ImageViewerPagerAdapter.this);
}
}
@Override
public void onError() {
}
});
}
container.addView(view);
return view;
}
@Override
public void onViewTap(View view, float v, float v1) {
Toaster.make(context,"hello");
((ImageViewPagerActivity) context).animateToolbar();
}
}
なぜPhotoViewAttacherを1つ共有していますか?各PhotoViewオブジェクトに独自のPhotoViewAttacherを持たせるべきですか? – JohnWowUs