Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 移动滚动视图时移动的像素数_Android_Scroll_Scrollview_Move_Pixels - Fatal编程技术网

Android 移动滚动视图时移动的像素数

Android 移动滚动视图时移动的像素数,android,scroll,scrollview,move,pixels,Android,Scroll,Scrollview,Move,Pixels,我已经试过好几次了,但都解决不了。 我有一个包含多个视图的滚动视图,这些视图由ObjectAnimator移动。当您按下按钮时,视图将在给定时间内垂直移动。 我确实会播放和暂停,但当我用手指移动滚动条时,我无法知道滚动条已移动的像素数 我想用我的手指移动卷轴,脉冲播放,我想卷轴开始滚动我放在哪里,而不是从一开始。 我试过这个: view.setOnTouchListener(new OnTouchListener() { @Override publi

我已经试过好几次了,但都解决不了。 我有一个包含多个视图的滚动视图,这些视图由ObjectAnimator移动。当您按下按钮时,视图将在给定时间内垂直移动。 我确实会播放和暂停,但当我用手指移动滚动条时,我无法知道滚动条已移动的像素数

我想用我的手指移动卷轴,脉冲播放,我想卷轴开始滚动我放在哪里,而不是从一开始。 我试过这个:

view.setOnTouchListener(new OnTouchListener() {
           @Override
           public boolean onTouch(View v, MotionEvent event) {
               //Choose which motion action has been performed
               switch(event.getAction())
               {
               case MotionEvent.ACTION_DOWN:
                   //Get X, Y coordinates from the ImageView
                   X = (int) event.getX();
                   Y = (int) event.getY();
                   startX = event.getRawX();
                   startY = event.getRawY();
                   break;
               case MotionEvent.ACTION_MOVE:
                  Z = (int) event.getX();
                   S = (int) event.getY();
                   K = (int) event.getRawX();
                   P = (int) event.getRawY();
                   V = (int) (event.getRawY() - startY);
                   break;
               case MotionEvent.ACTION_UP:
                   A = (int) event.getX();
                   E = (int) event.getY();
                   break;
               }
               return true;
           }
}))

当我抬起手指时,它不会给出坐标。当我移动卷轴时,我如何知道移动的像素数?这是一个Android应用程序。
提前谢谢

每次获得
动作移动
事件时,只需计算x和y坐标之间的差值即可。试着这样做:

public abstract class ScrollTouchListener implements View.OnTouchListener {

    private double x = 0;
    private double y = 0;

    @Override
    public boolean onTouch(View view, MotionEvent event) {    

        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                // User started scrolling
                x = event.getX();
                y = event.getY();
                onScrollStarted(x, y);
                return true;

            case MotionEvent.ACTION_UP:
                // User stopped scrolling
                x = event.getX();
                y = event.getY();
                onScrollEnded(x, y);
                return true;

            case MotionEvent.ACTION_MOVE:
                // Finger was moved get new x and y coordinates 
                // and calculate the difference
                double newX = event.getX();
                double newY = event.getY();

                double difX =  x - newX;
                double difY =  y - newY;

                onScroll(difX, difY);

                x = newX;
                y = newY;
                return true;

            default:
                return false;
        }
    }

    protected abstract void onScrollStarted(double x, double y);
    protected abstract void onScroll(double deltaX, double deltaY);
    protected abstract void onScrollEnded(double x, double y);
}
scrollView.setOnTouchListener(new ScrollTouchListener() {
    @Override
    protected void onScrollStarted(double x, double y) {
        // Called when you start scrolling. 
        // x and y are the coordinates where the user started scrolling.     
    }

    @Override
    protected void onScroll(double deltaX, double deltaY) {
        // Called while scrolling. 
        // deltaX and deltaY tell you how much the finger was moved.
    }

    @Override
    protected void onScrollEnded(double x, double y) {
        // Called when you stop scrolling. 
        // x and y are the coordinates where the user stopped scrolling.  
    }
});
您可以这样使用它:

public abstract class ScrollTouchListener implements View.OnTouchListener {

    private double x = 0;
    private double y = 0;

    @Override
    public boolean onTouch(View view, MotionEvent event) {    

        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                // User started scrolling
                x = event.getX();
                y = event.getY();
                onScrollStarted(x, y);
                return true;

            case MotionEvent.ACTION_UP:
                // User stopped scrolling
                x = event.getX();
                y = event.getY();
                onScrollEnded(x, y);
                return true;

            case MotionEvent.ACTION_MOVE:
                // Finger was moved get new x and y coordinates 
                // and calculate the difference
                double newX = event.getX();
                double newY = event.getY();

                double difX =  x - newX;
                double difY =  y - newY;

                onScroll(difX, difY);

                x = newX;
                y = newY;
                return true;

            default:
                return false;
        }
    }

    protected abstract void onScrollStarted(double x, double y);
    protected abstract void onScroll(double deltaX, double deltaY);
    protected abstract void onScrollEnded(double x, double y);
}
scrollView.setOnTouchListener(new ScrollTouchListener() {
    @Override
    protected void onScrollStarted(double x, double y) {
        // Called when you start scrolling. 
        // x and y are the coordinates where the user started scrolling.     
    }

    @Override
    protected void onScroll(double deltaX, double deltaY) {
        // Called while scrolling. 
        // deltaX and deltaY tell you how much the finger was moved.
    }

    @Override
    protected void onScrollEnded(double x, double y) {
        // Called when you stop scrolling. 
        // x and y are the coordinates where the user stopped scrolling.  
    }
});

每次获得
动作移动
事件时,您只需计算x和y坐标之间的差值。试着这样做:

public abstract class ScrollTouchListener implements View.OnTouchListener {

    private double x = 0;
    private double y = 0;

    @Override
    public boolean onTouch(View view, MotionEvent event) {    

        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                // User started scrolling
                x = event.getX();
                y = event.getY();
                onScrollStarted(x, y);
                return true;

            case MotionEvent.ACTION_UP:
                // User stopped scrolling
                x = event.getX();
                y = event.getY();
                onScrollEnded(x, y);
                return true;

            case MotionEvent.ACTION_MOVE:
                // Finger was moved get new x and y coordinates 
                // and calculate the difference
                double newX = event.getX();
                double newY = event.getY();

                double difX =  x - newX;
                double difY =  y - newY;

                onScroll(difX, difY);

                x = newX;
                y = newY;
                return true;

            default:
                return false;
        }
    }

    protected abstract void onScrollStarted(double x, double y);
    protected abstract void onScroll(double deltaX, double deltaY);
    protected abstract void onScrollEnded(double x, double y);
}
scrollView.setOnTouchListener(new ScrollTouchListener() {
    @Override
    protected void onScrollStarted(double x, double y) {
        // Called when you start scrolling. 
        // x and y are the coordinates where the user started scrolling.     
    }

    @Override
    protected void onScroll(double deltaX, double deltaY) {
        // Called while scrolling. 
        // deltaX and deltaY tell you how much the finger was moved.
    }

    @Override
    protected void onScrollEnded(double x, double y) {
        // Called when you stop scrolling. 
        // x and y are the coordinates where the user stopped scrolling.  
    }
});
您可以这样使用它:

public abstract class ScrollTouchListener implements View.OnTouchListener {

    private double x = 0;
    private double y = 0;

    @Override
    public boolean onTouch(View view, MotionEvent event) {    

        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                // User started scrolling
                x = event.getX();
                y = event.getY();
                onScrollStarted(x, y);
                return true;

            case MotionEvent.ACTION_UP:
                // User stopped scrolling
                x = event.getX();
                y = event.getY();
                onScrollEnded(x, y);
                return true;

            case MotionEvent.ACTION_MOVE:
                // Finger was moved get new x and y coordinates 
                // and calculate the difference
                double newX = event.getX();
                double newY = event.getY();

                double difX =  x - newX;
                double difY =  y - newY;

                onScroll(difX, difY);

                x = newX;
                y = newY;
                return true;

            default:
                return false;
        }
    }

    protected abstract void onScrollStarted(double x, double y);
    protected abstract void onScroll(double deltaX, double deltaY);
    protected abstract void onScrollEnded(double x, double y);
}
scrollView.setOnTouchListener(new ScrollTouchListener() {
    @Override
    protected void onScrollStarted(double x, double y) {
        // Called when you start scrolling. 
        // x and y are the coordinates where the user started scrolling.     
    }

    @Override
    protected void onScroll(double deltaX, double deltaY) {
        // Called while scrolling. 
        // deltaX and deltaY tell you how much the finger was moved.
    }

    @Override
    protected void onScrollEnded(double x, double y) {
        // Called when you stop scrolling. 
        // x and y are the coordinates where the user stopped scrolling.  
    }
});

每次获得
动作移动
事件时,您只需计算x和y坐标之间的差值。试着这样做:

public abstract class ScrollTouchListener implements View.OnTouchListener {

    private double x = 0;
    private double y = 0;

    @Override
    public boolean onTouch(View view, MotionEvent event) {    

        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                // User started scrolling
                x = event.getX();
                y = event.getY();
                onScrollStarted(x, y);
                return true;

            case MotionEvent.ACTION_UP:
                // User stopped scrolling
                x = event.getX();
                y = event.getY();
                onScrollEnded(x, y);
                return true;

            case MotionEvent.ACTION_MOVE:
                // Finger was moved get new x and y coordinates 
                // and calculate the difference
                double newX = event.getX();
                double newY = event.getY();

                double difX =  x - newX;
                double difY =  y - newY;

                onScroll(difX, difY);

                x = newX;
                y = newY;
                return true;

            default:
                return false;
        }
    }

    protected abstract void onScrollStarted(double x, double y);
    protected abstract void onScroll(double deltaX, double deltaY);
    protected abstract void onScrollEnded(double x, double y);
}
scrollView.setOnTouchListener(new ScrollTouchListener() {
    @Override
    protected void onScrollStarted(double x, double y) {
        // Called when you start scrolling. 
        // x and y are the coordinates where the user started scrolling.     
    }

    @Override
    protected void onScroll(double deltaX, double deltaY) {
        // Called while scrolling. 
        // deltaX and deltaY tell you how much the finger was moved.
    }

    @Override
    protected void onScrollEnded(double x, double y) {
        // Called when you stop scrolling. 
        // x and y are the coordinates where the user stopped scrolling.  
    }
});
您可以这样使用它:

public abstract class ScrollTouchListener implements View.OnTouchListener {

    private double x = 0;
    private double y = 0;

    @Override
    public boolean onTouch(View view, MotionEvent event) {    

        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                // User started scrolling
                x = event.getX();
                y = event.getY();
                onScrollStarted(x, y);
                return true;

            case MotionEvent.ACTION_UP:
                // User stopped scrolling
                x = event.getX();
                y = event.getY();
                onScrollEnded(x, y);
                return true;

            case MotionEvent.ACTION_MOVE:
                // Finger was moved get new x and y coordinates 
                // and calculate the difference
                double newX = event.getX();
                double newY = event.getY();

                double difX =  x - newX;
                double difY =  y - newY;

                onScroll(difX, difY);

                x = newX;
                y = newY;
                return true;

            default:
                return false;
        }
    }

    protected abstract void onScrollStarted(double x, double y);
    protected abstract void onScroll(double deltaX, double deltaY);
    protected abstract void onScrollEnded(double x, double y);
}
scrollView.setOnTouchListener(new ScrollTouchListener() {
    @Override
    protected void onScrollStarted(double x, double y) {
        // Called when you start scrolling. 
        // x and y are the coordinates where the user started scrolling.     
    }

    @Override
    protected void onScroll(double deltaX, double deltaY) {
        // Called while scrolling. 
        // deltaX and deltaY tell you how much the finger was moved.
    }

    @Override
    protected void onScrollEnded(double x, double y) {
        // Called when you stop scrolling. 
        // x and y are the coordinates where the user stopped scrolling.  
    }
});

每次获得
动作移动
事件时,您只需计算x和y坐标之间的差值。试着这样做:

public abstract class ScrollTouchListener implements View.OnTouchListener {

    private double x = 0;
    private double y = 0;

    @Override
    public boolean onTouch(View view, MotionEvent event) {    

        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                // User started scrolling
                x = event.getX();
                y = event.getY();
                onScrollStarted(x, y);
                return true;

            case MotionEvent.ACTION_UP:
                // User stopped scrolling
                x = event.getX();
                y = event.getY();
                onScrollEnded(x, y);
                return true;

            case MotionEvent.ACTION_MOVE:
                // Finger was moved get new x and y coordinates 
                // and calculate the difference
                double newX = event.getX();
                double newY = event.getY();

                double difX =  x - newX;
                double difY =  y - newY;

                onScroll(difX, difY);

                x = newX;
                y = newY;
                return true;

            default:
                return false;
        }
    }

    protected abstract void onScrollStarted(double x, double y);
    protected abstract void onScroll(double deltaX, double deltaY);
    protected abstract void onScrollEnded(double x, double y);
}
scrollView.setOnTouchListener(new ScrollTouchListener() {
    @Override
    protected void onScrollStarted(double x, double y) {
        // Called when you start scrolling. 
        // x and y are the coordinates where the user started scrolling.     
    }

    @Override
    protected void onScroll(double deltaX, double deltaY) {
        // Called while scrolling. 
        // deltaX and deltaY tell you how much the finger was moved.
    }

    @Override
    protected void onScrollEnded(double x, double y) {
        // Called when you stop scrolling. 
        // x and y are the coordinates where the user stopped scrolling.  
    }
});
您可以这样使用它:

public abstract class ScrollTouchListener implements View.OnTouchListener {

    private double x = 0;
    private double y = 0;

    @Override
    public boolean onTouch(View view, MotionEvent event) {    

        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                // User started scrolling
                x = event.getX();
                y = event.getY();
                onScrollStarted(x, y);
                return true;

            case MotionEvent.ACTION_UP:
                // User stopped scrolling
                x = event.getX();
                y = event.getY();
                onScrollEnded(x, y);
                return true;

            case MotionEvent.ACTION_MOVE:
                // Finger was moved get new x and y coordinates 
                // and calculate the difference
                double newX = event.getX();
                double newY = event.getY();

                double difX =  x - newX;
                double difY =  y - newY;

                onScroll(difX, difY);

                x = newX;
                y = newY;
                return true;

            default:
                return false;
        }
    }

    protected abstract void onScrollStarted(double x, double y);
    protected abstract void onScroll(double deltaX, double deltaY);
    protected abstract void onScrollEnded(double x, double y);
}
scrollView.setOnTouchListener(new ScrollTouchListener() {
    @Override
    protected void onScrollStarted(double x, double y) {
        // Called when you start scrolling. 
        // x and y are the coordinates where the user started scrolling.     
    }

    @Override
    protected void onScroll(double deltaX, double deltaY) {
        // Called while scrolling. 
        // deltaX and deltaY tell you how much the finger was moved.
    }

    @Override
    protected void onScrollEnded(double x, double y) {
        // Called when you stop scrolling. 
        // x and y are the coordinates where the user stopped scrolling.  
    }
});

这是我的解决方案,工作完美,尝试阅读代码

public class CustomScrollView extends NestedScrollView
{

private boolean mIsScrolling;
private boolean mIsTouching;
private OnScrollListener mOnScrollListener;
private Runnable mScrollingRunnable;

public interface OnScrollListener
{
    void onScrollChanged(CustomScrollView scrollView, int x, int y, int oldX, int oldY);

    void onEndScroll(CustomScrollView scrollView);

    void onGoUp();

    void onGoDown();
}

public CustomScrollView(final Context context)
{
    super(context);
}

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

public CustomScrollView(final Context context, final AttributeSet attrs, final int defStyleAttr)
{
    super(context, attrs, defStyleAttr);
}

private int y = 0;

@Override
public boolean dispatchTouchEvent(MotionEvent iEv)
{
    if (isEnabled())
    {

        processEvent(iEv);

        super.dispatchTouchEvent(iEv);

        return true; //to keep receive event that follow down event
    }
    return super.dispatchTouchEvent(iEv);
}

private void processEvent(final MotionEvent iEv)
{
    switch (iEv.getAction())
    {
        case MotionEvent.ACTION_DOWN:
            y = (int) iEv.getY();
            break;

        case MotionEvent.ACTION_UP:
            y = (int) iEv.getY();

            if (mIsTouching && !mIsScrolling)
            {
                if (mOnScrollListener != null)
                {
                    //If you need to know when end of scrolling just uncomment
                    mOnScrollListener.onEndScroll(this);
                }
            }

            mIsTouching = false;
            break;
        case MotionEvent.ACTION_MOVE:
            mIsTouching = true;
            mIsScrolling = true;

            int newY = (int) iEv.getY();
            int difY = y - newY;

            int MAX_VALUE = 200;
            int MIN_VALUE = -200;
            if (difY > MAX_VALUE)
            {
                AppUtils.printLog(Log.ERROR, "TAG", "difY down : " + difY + " , y : " + y + ", newY : " + newY);
                if (mOnScrollListener != null)
                {
                    mOnScrollListener.onGoDown();
                }
                y = newY;
            }
            else if (difY < MIN_VALUE)
            {
                AppUtils.printLog(Log.ERROR, "TAG", "difY  up : " + difY + " , y : " + y + ", newY : " + newY);
                if (mOnScrollListener != null)
                {
                    mOnScrollListener.onGoUp();
                }
                y = newY;
            }

            break;
    }
}

@Override
protected void onScrollChanged(int iX, int iY, int iOldX, int iOldY)
{
    super.onScrollChanged(iX, iY, iOldX, iOldY);

    if (Math.abs(iOldX - iX) > 0)
    {
        if (mScrollingRunnable != null)
        {
            removeCallbacks(mScrollingRunnable);
        }

        mScrollingRunnable = new Runnable()
        {
            public void run()
            {
                if (mIsScrolling && !mIsTouching)
                {
                    if (mOnScrollListener != null)
                    {
                        mOnScrollListener.onEndScroll(CustomScrollView.this);
                    }
                }

                mIsScrolling = false;
                mScrollingRunnable = null;
            }
        };

        postDelayed(mScrollingRunnable, 200);
    }

    if (mOnScrollListener != null)
    {
        mOnScrollListener.onScrollChanged(this, iX, iY, iOldX, iOldY);
    }
}

public OnScrollListener getOnScrollListener()
{
    return mOnScrollListener;
}

public void setOnScrollListener(OnScrollListener mOnEndScrollListener)
{
    this.mOnScrollListener = mOnEndScrollListener;
}
}

这是我的解决方案,工作完美,尝试阅读代码

public class CustomScrollView extends NestedScrollView
{

private boolean mIsScrolling;
private boolean mIsTouching;
private OnScrollListener mOnScrollListener;
private Runnable mScrollingRunnable;

public interface OnScrollListener
{
    void onScrollChanged(CustomScrollView scrollView, int x, int y, int oldX, int oldY);

    void onEndScroll(CustomScrollView scrollView);

    void onGoUp();

    void onGoDown();
}

public CustomScrollView(final Context context)
{
    super(context);
}

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

public CustomScrollView(final Context context, final AttributeSet attrs, final int defStyleAttr)
{
    super(context, attrs, defStyleAttr);
}

private int y = 0;

@Override
public boolean dispatchTouchEvent(MotionEvent iEv)
{
    if (isEnabled())
    {

        processEvent(iEv);

        super.dispatchTouchEvent(iEv);

        return true; //to keep receive event that follow down event
    }
    return super.dispatchTouchEvent(iEv);
}

private void processEvent(final MotionEvent iEv)
{
    switch (iEv.getAction())
    {
        case MotionEvent.ACTION_DOWN:
            y = (int) iEv.getY();
            break;

        case MotionEvent.ACTION_UP:
            y = (int) iEv.getY();

            if (mIsTouching && !mIsScrolling)
            {
                if (mOnScrollListener != null)
                {
                    //If you need to know when end of scrolling just uncomment
                    mOnScrollListener.onEndScroll(this);
                }
            }

            mIsTouching = false;
            break;
        case MotionEvent.ACTION_MOVE:
            mIsTouching = true;
            mIsScrolling = true;

            int newY = (int) iEv.getY();
            int difY = y - newY;

            int MAX_VALUE = 200;
            int MIN_VALUE = -200;
            if (difY > MAX_VALUE)
            {
                AppUtils.printLog(Log.ERROR, "TAG", "difY down : " + difY + " , y : " + y + ", newY : " + newY);
                if (mOnScrollListener != null)
                {
                    mOnScrollListener.onGoDown();
                }
                y = newY;
            }
            else if (difY < MIN_VALUE)
            {
                AppUtils.printLog(Log.ERROR, "TAG", "difY  up : " + difY + " , y : " + y + ", newY : " + newY);
                if (mOnScrollListener != null)
                {
                    mOnScrollListener.onGoUp();
                }
                y = newY;
            }

            break;
    }
}

@Override
protected void onScrollChanged(int iX, int iY, int iOldX, int iOldY)
{
    super.onScrollChanged(iX, iY, iOldX, iOldY);

    if (Math.abs(iOldX - iX) > 0)
    {
        if (mScrollingRunnable != null)
        {
            removeCallbacks(mScrollingRunnable);
        }

        mScrollingRunnable = new Runnable()
        {
            public void run()
            {
                if (mIsScrolling && !mIsTouching)
                {
                    if (mOnScrollListener != null)
                    {
                        mOnScrollListener.onEndScroll(CustomScrollView.this);
                    }
                }

                mIsScrolling = false;
                mScrollingRunnable = null;
            }
        };

        postDelayed(mScrollingRunnable, 200);
    }

    if (mOnScrollListener != null)
    {
        mOnScrollListener.onScrollChanged(this, iX, iY, iOldX, iOldY);
    }
}

public OnScrollListener getOnScrollListener()
{
    return mOnScrollListener;
}

public void setOnScrollListener(OnScrollListener mOnEndScrollListener)
{
    this.mOnScrollListener = mOnEndScrollListener;
}
}

这是我的解决方案,工作完美,尝试阅读代码

public class CustomScrollView extends NestedScrollView
{

private boolean mIsScrolling;
private boolean mIsTouching;
private OnScrollListener mOnScrollListener;
private Runnable mScrollingRunnable;

public interface OnScrollListener
{
    void onScrollChanged(CustomScrollView scrollView, int x, int y, int oldX, int oldY);

    void onEndScroll(CustomScrollView scrollView);

    void onGoUp();

    void onGoDown();
}

public CustomScrollView(final Context context)
{
    super(context);
}

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

public CustomScrollView(final Context context, final AttributeSet attrs, final int defStyleAttr)
{
    super(context, attrs, defStyleAttr);
}

private int y = 0;

@Override
public boolean dispatchTouchEvent(MotionEvent iEv)
{
    if (isEnabled())
    {

        processEvent(iEv);

        super.dispatchTouchEvent(iEv);

        return true; //to keep receive event that follow down event
    }
    return super.dispatchTouchEvent(iEv);
}

private void processEvent(final MotionEvent iEv)
{
    switch (iEv.getAction())
    {
        case MotionEvent.ACTION_DOWN:
            y = (int) iEv.getY();
            break;

        case MotionEvent.ACTION_UP:
            y = (int) iEv.getY();

            if (mIsTouching && !mIsScrolling)
            {
                if (mOnScrollListener != null)
                {
                    //If you need to know when end of scrolling just uncomment
                    mOnScrollListener.onEndScroll(this);
                }
            }

            mIsTouching = false;
            break;
        case MotionEvent.ACTION_MOVE:
            mIsTouching = true;
            mIsScrolling = true;

            int newY = (int) iEv.getY();
            int difY = y - newY;

            int MAX_VALUE = 200;
            int MIN_VALUE = -200;
            if (difY > MAX_VALUE)
            {
                AppUtils.printLog(Log.ERROR, "TAG", "difY down : " + difY + " , y : " + y + ", newY : " + newY);
                if (mOnScrollListener != null)
                {
                    mOnScrollListener.onGoDown();
                }
                y = newY;
            }
            else if (difY < MIN_VALUE)
            {
                AppUtils.printLog(Log.ERROR, "TAG", "difY  up : " + difY + " , y : " + y + ", newY : " + newY);
                if (mOnScrollListener != null)
                {
                    mOnScrollListener.onGoUp();
                }
                y = newY;
            }

            break;
    }
}

@Override
protected void onScrollChanged(int iX, int iY, int iOldX, int iOldY)
{
    super.onScrollChanged(iX, iY, iOldX, iOldY);

    if (Math.abs(iOldX - iX) > 0)
    {
        if (mScrollingRunnable != null)
        {
            removeCallbacks(mScrollingRunnable);
        }

        mScrollingRunnable = new Runnable()
        {
            public void run()
            {
                if (mIsScrolling && !mIsTouching)
                {
                    if (mOnScrollListener != null)
                    {
                        mOnScrollListener.onEndScroll(CustomScrollView.this);
                    }
                }

                mIsScrolling = false;
                mScrollingRunnable = null;
            }
        };

        postDelayed(mScrollingRunnable, 200);
    }

    if (mOnScrollListener != null)
    {
        mOnScrollListener.onScrollChanged(this, iX, iY, iOldX, iOldY);
    }
}

public OnScrollListener getOnScrollListener()
{
    return mOnScrollListener;
}

public void setOnScrollListener(OnScrollListener mOnEndScrollListener)
{
    this.mOnScrollListener = mOnEndScrollListener;
}
}

这是我的解决方案,工作完美,尝试阅读代码

public class CustomScrollView extends NestedScrollView
{

private boolean mIsScrolling;
private boolean mIsTouching;
private OnScrollListener mOnScrollListener;
private Runnable mScrollingRunnable;

public interface OnScrollListener
{
    void onScrollChanged(CustomScrollView scrollView, int x, int y, int oldX, int oldY);

    void onEndScroll(CustomScrollView scrollView);

    void onGoUp();

    void onGoDown();
}

public CustomScrollView(final Context context)
{
    super(context);
}

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

public CustomScrollView(final Context context, final AttributeSet attrs, final int defStyleAttr)
{
    super(context, attrs, defStyleAttr);
}

private int y = 0;

@Override
public boolean dispatchTouchEvent(MotionEvent iEv)
{
    if (isEnabled())
    {

        processEvent(iEv);

        super.dispatchTouchEvent(iEv);

        return true; //to keep receive event that follow down event
    }
    return super.dispatchTouchEvent(iEv);
}

private void processEvent(final MotionEvent iEv)
{
    switch (iEv.getAction())
    {
        case MotionEvent.ACTION_DOWN:
            y = (int) iEv.getY();
            break;

        case MotionEvent.ACTION_UP:
            y = (int) iEv.getY();

            if (mIsTouching && !mIsScrolling)
            {
                if (mOnScrollListener != null)
                {
                    //If you need to know when end of scrolling just uncomment
                    mOnScrollListener.onEndScroll(this);
                }
            }

            mIsTouching = false;
            break;
        case MotionEvent.ACTION_MOVE:
            mIsTouching = true;
            mIsScrolling = true;

            int newY = (int) iEv.getY();
            int difY = y - newY;

            int MAX_VALUE = 200;
            int MIN_VALUE = -200;
            if (difY > MAX_VALUE)
            {
                AppUtils.printLog(Log.ERROR, "TAG", "difY down : " + difY + " , y : " + y + ", newY : " + newY);
                if (mOnScrollListener != null)
                {
                    mOnScrollListener.onGoDown();
                }
                y = newY;
            }
            else if (difY < MIN_VALUE)
            {
                AppUtils.printLog(Log.ERROR, "TAG", "difY  up : " + difY + " , y : " + y + ", newY : " + newY);
                if (mOnScrollListener != null)
                {
                    mOnScrollListener.onGoUp();
                }
                y = newY;
            }

            break;
    }
}

@Override
protected void onScrollChanged(int iX, int iY, int iOldX, int iOldY)
{
    super.onScrollChanged(iX, iY, iOldX, iOldY);

    if (Math.abs(iOldX - iX) > 0)
    {
        if (mScrollingRunnable != null)
        {
            removeCallbacks(mScrollingRunnable);
        }

        mScrollingRunnable = new Runnable()
        {
            public void run()
            {
                if (mIsScrolling && !mIsTouching)
                {
                    if (mOnScrollListener != null)
                    {
                        mOnScrollListener.onEndScroll(CustomScrollView.this);
                    }
                }

                mIsScrolling = false;
                mScrollingRunnable = null;
            }
        };

        postDelayed(mScrollingRunnable, 200);
    }

    if (mOnScrollListener != null)
    {
        mOnScrollListener.onScrollChanged(this, iX, iY, iOldX, iOldY);
    }
}

public OnScrollListener getOnScrollListener()
{
    return mOnScrollListener;
}

public void setOnScrollListener(OnScrollListener mOnEndScrollListener)
{
    this.mOnScrollListener = mOnEndScrollListener;
}
}

您已经采取了正确的方法,但这些变量是什么<代码>S,
K
P
V
A
E
Z
X
Y
?你为什么需要它们?你只需要计算x和y坐标之间的差值就可以得到手指移动的程度。你已经采取了正确的方法,但是这些变量是什么<代码>S,
K
P
V
A
E
Z
X
Y
?你为什么需要它们?你只需要计算x和y坐标之间的差值就可以得到手指移动的程度。你已经采取了正确的方法,但是这些变量是什么<代码>S,
K
P
V
A
E
Z
X
Y
?你为什么需要它们?你只需要计算x和y坐标之间的差值就可以得到手指移动的程度。你已经采取了正确的方法,但是这些变量是什么<代码>S,
K
P
V
A
E
Z
X
Y
?你为什么需要它们?你只需要计算x和y坐标之间的差值就可以得到手指的移动量。也许这是一个很好的解决方案,但在我的例子中它不起作用。它计算从顶部的偏移量,即增量,但它阻止滚动。请参阅。@CoolMind设置触控式侦听器并使用触控事件当然意味着
滚动视图将不会滚动。这是重点。也许这是一个很好的解决方案,但在我的情况下,它不起作用。它计算从顶部的偏移量,即增量,但它阻止滚动。请参阅。@CoolMind设置触控式侦听器并使用触控事件当然意味着
滚动视图将不会滚动。这是重点。也许这是一个很好的解决方案,但在我的情况下,它不起作用。它计算从顶部的偏移量,即增量,但它阻止滚动。请参阅。@CoolMind设置触控式侦听器并使用触控事件当然意味着
滚动视图将不会滚动。这是重点。也许这是一个很好的解决方案,但在我的情况下,它不起作用。它计算从顶部的偏移量,即增量,但它阻止滚动。请参阅。@CoolMind设置触控式侦听器并使用触控事件当然意味着
滚动视图将不会滚动。这就是重点。