@SuppressLint("ClickableViewAccessibility")
    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        if (!isManuallyScrollLocked()) {
            if (mVelocityTracker == null) {
                mVelocityTracker = VelocityTracker.obtain();
            }
            mVelocityTracker.addMovement(ev);
        }
        int x = (int) ev.getX();
        int y = (int) ev.getY();
        switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN:
                if (!mScroller.isFinished() && !isManuallyScrollLocked()) {
                    mScroller.abortAnimation();
                }
                mLastX = mLastDownX = x;
                mLastDownY = y;
                mIsTouching = true;
                break;
            case MotionEvent.ACTION_MOVE:
                if (!isManuallyScrollLocked()) {
                    int dx = mLastX - x;
                    if (isCurrentScrollAllowed(mPager.mCurrentPosition, dx > 0)) {
                        scrollBy(dx, 0);
                    }
                    if (Math.abs(mLastDownX - x) > 20) {
                        requestDisallowInterceptTouchEvent(true);
                    }
                }
                mLastX = x;
                break;
            case MotionEvent.ACTION_OUTSIDE:
            case MotionEvent.ACTION_CANCEL:
                if (x != mLastDownX) {
                    slowScrollToPage();
                }
                touchFinished();
                break;
            case MotionEvent.ACTION_UP:
                float outsideEachPercent = (1f - mForegroundWidthPercent) / 2;
                if (Math.abs(mLastDownX - x) < 20
                        && Math.abs(mLastDownY - y) < 20
                        && !performClick()) {
                    if (x > getWidth() * outsideEachPercent && x < getWidth() * (1 - outsideEachPercent)) {
                        handleClick();
                    } else if (!isManuallyScrollLocked()) {
                        if (x < getWidth() * outsideEachPercent) {
                            goPreviousPage();
                        } else {
                            goNextPage();
                        }
                    }
                } else if (!isManuallyScrollLocked()) {
                    handleScroll();
                }
                touchFinished();
                break;
            default:
                mIsTouching = false;
                break;
        }
        return true;
    }
A banner view that can automatically or manually scroll in a loop
Created by Marksss on 2019/8/12.
imitate/src/main/java/com/engineer/imitate/ui/widget/opensource/InfiniteBannerView.java