I am using VerticalViewPagerand TouchImageView for image zoom in/out. When i zoom in on the image and try to drag the image down (to view the bottom part of image) the view pager swipes to second image. Any help would be appreciate. I need to disable the viewpager i tried to change the canScroll function of vertical view pager but it didnt help.
Here is the code that i modified:
protected boolean canScroll(View v, boolean checkV, int dy, int x, int y) {
if(v instanceof TouchImageView)
{
Log.d("Here","Here");
if(((TouchImageView) v).getCurrentZoom()!=1)
{
Log.d("Here","HereAgain");
return false;
}
}
else if (v instanceof ViewGroup) {
final ViewGroup group = (ViewGroup) v;
final int scrollX = v.getScrollX();
final int scrollY = v.getScrollY();
final int count = group.getChildCount();
// Count backwards - let topmost views consume scroll distance first.
for (int i = count - 1; i >= 0; i--) {
// TODO: Add versioned support here for transformed views.
// This will not work for transformed views in Honeycomb+
final View child = group.getChildAt(i);
if (y + scrollY >= child.getTop() && y + scrollY < child.getBottom() &&
x + scrollX >= child.getLeft() && x + scrollX < child.getRight() &&
canScroll(child, true, dy, x + scrollX - child.getLeft(),
y + scrollY - child.getTop())) {
return true;
}
}
return checkV && ViewCompat.canScrollVertically(v, -dy);
}
return false;
}
To solve that, create a custom
VerticalViewPager
class which overrides the scroll events (onTouchEvent
,onInterceptTouchEvent
), then return from ittrue
orfalse
depending on if you want to scroll or not, and that will achieved through a predefined Boolean variable:and to define :
So, you can toggle anytime between
true
andfalse
to allow and disable scrolling usingcustom_vvp.setScroll()
method.