2

当我旋转设备时,如果我选择了第一个或最后一个以外的选项卡,它会显示选项卡的错误位置。

但是当我做出一点触摸手势时,它会自行更新。你知道如何解决这个问题。

4

2 回答 2

5

这很简单,见下文

getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

        @SuppressWarnings("deprecation")
        @SuppressLint("NewApi")
        @Override
        public void onGlobalLayout() {

            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                getViewTreeObserver().removeGlobalOnLayoutListener(this);
            } else {
                getViewTreeObserver().removeOnGlobalLayoutListener(this);
            }

            currentPosition = pager.getCurrentItem();
            currentPositionOffset = 0f; // ----> just put this line
            scrollToChild(currentPosition, 0);
        }
    });
于 2014-02-27T06:57:07.177 回答
1

当我删除调用方法时,它对我有用setPageMargin()

于 2015-09-19T07:12:46.603 回答