PagerSlidingTabStrip icon indicating copy to clipboard operation
PagerSlidingTabStrip copied to clipboard

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

Open lyx0224 opened this issue 7 years ago • 2 comments

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

lyx0224 avatar Jan 20 '18 02:01 lyx0224

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

lixiaote avatar Mar 06 '19 07:03 lixiaote

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);
}

});

lixiaote avatar Mar 06 '19 07:03 lixiaote