Closed adeldolgov closed 5 years ago
If you're swiping on the actual image, it's going to prioritize translating and/or zooming the image over swiping pages.
Then how can i swipe horizontally, if i have full match parent zoomageView?
Also is there any zoom listener avalaible?
Can you check to see if it works by setting translatable to false?
It works, but then i can't swipe on image
If you have zoom listener, then i can just disable ViewPager paging, and reenable when picture zoomout
currently there isn't but you could override onTouchEvent and check the current zoom factor there and make your calls, then return super.onTouchEvent
A zoom listener has been requested and I am planning to add it sometime soon though. In the mean time I would try the suggestion above.
How can i check inside onTouchEvent if image was zoomed?
getCurrentScaleFactor
Thanks! I fixed the issue.
! version 1.2.0
implementation 'com.jsibbold:zoomage:1.2.0'
Thanks @jsibbold for help!
Let me explain how i fixed it : Inside your CustomPagerAdapter :
OnImageZoomListener listener;
public void setOnImageZoomListener(OnImageZoomListener listener) {
this.listener = listener;
}
public interface OnImageZoomListener
{
void onImageZoomed(boolean isZoomed);
}
Inside overrided instantiateItem method of CustomPagerAdapter
@Override
public Object instantiateItem(ViewGroup collection, int position) {
LayoutInflater inflater = LayoutInflater.from(mContext);
ViewGroup layout = (ViewGroup) inflater.inflate(R.layout.item_galerry_detail, collection, false);
ZoomageView zoomageView = layout.findViewById(R.id.zoomageView);
zoomageView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(zoomageView.getCurrentScaleFactor()>1f || zoomageView.getCurrentScaleFactor()<1f)
listener.onImageZoomed(true);
else
listener.onImageZoomed(false);
return zoomageView.onTouchEvent(event);
}
});
}
Then on Activity/Fragment
CustomPagerAdapter customPagerAdapter;
customPagerAdapter.setOnImageZoomListener(new CustomPagerAdapter.OnImageZoomListener() {
@Override
public void onImageZoomed(boolean isZoomed) {
if(isZoomed)
customViewPager.setPagingEnabled(false);
else
customViewPager.setPagingEnabled(true);
}
});
Glad you got it working, it's a difficult thing figuring out how to prioritize overlapped touchable views. I may consider adding a bit of logic specifically for views that have not been zoomed at all, for translation. The only potential problem I see there is if someone has centerCropped an image and it's bigger than the visible area, they wouldn't be able to translate and may want to.
Okay. Thank you for the library!
@jsibbold this solution allows to move picture left/right sides when picture zoomed inside ViewPager item. Without this when you using horizontal scrolling it will change picture (or ViewPager item), not move zoom. You can tag it somehow if you want, maybe this will be helpful for some users.
Awesome solution. Just one change now while using viewpager2(new component) is :
zoomageView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if(zoomageView.getCurrentScaleFactor()>1f || zoomageView.getCurrentScaleFactor()<1f) {
listener.onImageZoomed(true);
zoomageView.setTranslatable(true);
}
else {
listener.onImageZoomed(false);
zoomageView.setTranslatable(false);
}
return zoomageView.onTouchEvent(motionEvent);
}
});
I'll work on a solution for this problem in the next snapshot. I would want to add some options for it so devs can decide whether they want this behavior or not.
After update to 1.3.0 i can't swipe to left right inside viewpager. How can i fix it? I can't change images