@Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        if (getChildCount() == 0 || mAdapter == null) {
            return;
        }
        int outsideLength = (int) (getMeasuredWidth() * (1f - mForegroundWidthPercent) / 2);
        int periodLength = getPeriodLength(getMeasuredWidth());
        if (mPager.isSkippingPosition()) {
            // refresh the layout after reset
            int head = mPager.mCurrentPosition - getDepthWithCache();
            int tail = mPager.mCurrentPosition + getDepthWithCache();
            while (head <= tail) {
                if (head == tail) {
                    childLayout(getViewOnPosition(head), periodLength, outsideLength, head);
                } else {
                    childLayout(getViewOnPosition(head), periodLength, outsideLength, head);
                    childLayout(getViewOnPosition(tail), periodLength, outsideLength, tail);
                }
                head++;
                tail--;
            }
        } else if (mPager.isPreviousPosition()) {
            // scroll to the previous position
            childLayout(getViewOnPosition(mPager.mPositionLastRelayout + getDepthWithCache()),
                    periodLength, outsideLength, mPager.mPositionLastRelayout - getDepthWithCache() - 1);
        } else if (mPager.isNextPosition()) {
            // scroll to the next position
            childLayout(getViewOnPosition(mPager.mPositionLastRelayout - getDepthWithCache()),
                    periodLength, outsideLength, mPager.mPositionLastRelayout + getDepthWithCache() + 1);
        }
        mPager.recordWhenRelayout();
    }
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