private void recomputeScrollPosition(int height, int oldHeight, int margin, int oldMargin) {
        if (oldHeight > 0 && !mItems.isEmpty()) {
            final int heightWithMargin = height - getPaddingTop() - getPaddingBottom() + margin;
            final int oldHeightWithMargin = oldHeight - getPaddingTop() - getPaddingBottom()
                    + oldMargin;
            final int ypos = getScrollY();
            final float pageOffset = (float) ypos / oldHeightWithMargin;
            final int newOffsetPixels = (int) (pageOffset * heightWithMargin);

            scrollTo(getScrollX(), newOffsetPixels);
            if (!mScroller.isFinished()) {
                // We now return to your regularly scheduled scroll, already in progress.
                final int newDuration = mScroller.getDuration() - mScroller.timePassed();
                ItemInfo targetInfo = infoForPosition(mCurItem);
                mScroller.startScroll(0, newOffsetPixels,
                        0, (int) (targetInfo.offset * height), newDuration);
            }
        } else {
            final ItemInfo ii = infoForPosition(mCurItem);
            final float scrollOffset = ii != null ? Math.min(ii.offset, mLastOffset) : 0;
            final int scrollPos = (int) (scrollOffset *
                    (height - getPaddingTop() - getPaddingBottom()));
            if (scrollPos != getScrollY()) {
                completeScroll(false);
                scrollTo(getScrollX(), scrollPos);
            }
        }
    }
This is the persistent state that is saved by ViewPager.  Only needed
if you are creating a sublass of ViewPager that must save its own
state, in which case it should implement a subclass of this which
contains that state.
dkplayer-sample/src/main/java/xyz/doikki/dkplayer/widget/VerticalViewPager.java