astuetz / PagerSlidingTabStrip

An interactive indicator to navigate between the different pages of a ViewPager
139 stars 44 forks source link

和viewpager一起使用,偶发tab和content错位 #321

Open lyx0224 opened 6 years ago

lyx0224 commented 6 years ago

场景:MainActivity使用了TabStrip + ViewPager布局。lanchmode=singleTask。从某个子页面回到MainActivity时候,偶发错位。

lixiaote commented 5 years ago

楼主这个问题解决了吗,我也遇到这个问题了

lixiaote commented 5 years ago

it is a bug. you can fix it by adding this line to the PagerSlidingTabStrip.java

加上这行就可以了 currentPositionOffset = 0;//source line number 220

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 = 0;//source line number 220
    scrollToChild(currentPosition, 0);
}

});