Skip to content

使用ViewTreeObserver.OnPreDrawListener接口计算totalDistance一些场景有比较大的问题 #5

Description

@momoandy

我的使用场景如下:
ViewPager+Fragment,Fragment中使用LoopViewPagerLayout。
正常使用以及滑动VP没问题;当快速滑动VP时,LoopViewPagerLayout无法释放ViewTreeObserver.OnPreDrawListener接口,导致无限调用一下代码:

publicbooleanonPreDraw() {
RectfirstRect = newRect();
indicatorLayout.getChildAt(0).getGlobalVisibleRect(firstRect);
L.e("firstRect = " + firstRect.toShortString());
RectlastRect = newRect();
indicatorLayout.getChildAt(indicators.length - 1).getGlobalVisibleRect(lastRect);
L.e("lastRect = " + lastRect.toShortString());
totalDistance = lastRect.left - firstRect.left;
L.e("totalDistance = " + totalDistance);
indicatorLayout.getViewTreeObserver().removeOnPreDrawListener(this);
returnfalse;
}

我的建议是放弃OnPreDrawListener接口,使用如下代码计算即可:

totalDistance = 2 * size * (indicators.length-1);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions