From e1baf34c5a457bf48e82a76a24c260d6ac27b578 Mon Sep 17 00:00:00 2001 From: Nikita Olifer Date: Wed, 21 Feb 2018 13:34:38 +0300 Subject: [PATCH] Check for illegal offset values in ViewPagerAdapter. --- .../scrollingpagerindicator/ViewPagerAttacher.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/library/src/main/java/ru/tinkoff/scrollingpagerindicator/ViewPagerAttacher.java b/library/src/main/java/ru/tinkoff/scrollingpagerindicator/ViewPagerAttacher.java index 3a6dc71..9c9d479 100644 --- a/library/src/main/java/ru/tinkoff/scrollingpagerindicator/ViewPagerAttacher.java +++ b/library/src/main/java/ru/tinkoff/scrollingpagerindicator/ViewPagerAttacher.java @@ -45,7 +45,16 @@ public void onInvalidated() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixel) { - indicator.onPageScrolled(position, positionOffset); + final float offset; + // ViewPager may emit negative positionOffset for very fast scrolling + if (positionOffset < 0) { + offset = 0; + } else if (positionOffset > 1) { + offset = 1; + } else { + offset = positionOffset; + } + indicator.onPageScrolled(position, offset); } @Override