0

我正在使用VerticalViewPagerTouchImageView进行图像放大/缩小。当我放大图像并尝试向下拖动图像(以查看图像的底部)时,视图寻呼机滑动到第二个图像。任何帮助将不胜感激。我需要禁用 viewpager 我试图更改垂直视图寻呼机的 canScroll 功能,但它没有帮助。

这是我修改的代码:

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;
}
4

2 回答 2

2

为了解决这个问题,创建一个VerticalViewPager覆盖滚动事件(onTouchEvent, onInterceptTouchEvent)的自定义类,然后从它返回truefalse根据您是否要滚动,这将通过预定义的布尔变量实现:

import android.content.Context;
import android.view.MotionEvent;

public class CustomizongVVP extends VerticalViewPager {

    public boolean scroll = true;

    public CustomizongVVP(Context context) {
        super(context);
    }

    public CustomizongVVP(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        return scroll && super.onTouchEvent(event);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent event) {
        return scroll && super.onInterceptTouchEvent(event);
    }

    public void setScroll(boolean scroll) {
        this.scroll = scroll;
    }

}

并定义:

CustomizongVVP custom_vvp = new CustomizongVVP(this);
custom_vvp.setScroll(true); // to allow scrolling
custom_vvp.setScroll(false); // to disable scrolling

true因此,您可以随时在和之间切换,false以允许和禁用使用custom_vvp.setScroll()方法滚动。

于 2014-12-07T11:14:53.693 回答
1

另一种方法是继承 TouchImageView 并覆盖 canScrollVertically 方法,如下所示:

@Override
public boolean canScrollVertically(int direction) {
    matrix.getValues(m);
    float y = m[Matrix.MTRANS_Y];

    if (getImageHeight() < viewHeight) {
        return false;

    } else if (y >= -1 && direction < 0) {
        return false;

    } else if (Math.abs(y) + viewHeight + 1 >= getImageHeight() && direction > 0) {
        return false;
    }

    return true;
}

如果图像被缩小,则滑动会改变页面。如果图像被放大,那么他们可以在图像周围平移而不改变页面,直到他们到达缩放图像的顶部或底部,此时下一次滑动将改变页面。

希望这会有所帮助

于 2015-10-26T12:02:50.807 回答