'Remove ViewPager2 Overscroll animation
Can't find a way to remove the ViewPager2 overscroll shadow animation. I know on ViewPager, you can directly just set the overscrollMode attribute to never, however, it does not work on ViewPager2
Already tried the following
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:overScrollMode="never"/>
binding.viewPager.apply {
adapter = adapter
orientation = ViewPager2.ORIENTATION_VERTICAL
overScrollMode = ViewPager2.OVER_SCROLL_NEVER
offscreenPageLimit = if (containsVideo) 2 else 5
}
Solution 1:[1]
In case anyone searching for a Java solution
View child = viewPager2.getChildAt(0);
if (child instanceof RecyclerView) {
child.setOverScrollMode(View.OVER_SCROLL_NEVER);
}
Solution 2:[2]
As Kotlin extension:
fun ViewPager2.removeOverScroll() {
(getChildAt(0) as? RecyclerView)?.overScrollMode = View.OVER_SCROLL_NEVER
}
and you are using it in your Fragment/Activity:
viewPager.removeOverScroll()
Solution 3:[3]
This one worked for me:
val child = binding.<your viewPager camelCase id>.getChildAt(0)
(child as? RecyclerView)?.overScrollMode = View.OVER_SCROLL_NEVER
Solution 4:[4]
My kotlin code version that work in my project, without binding:
// over scroll animation
val child: View = pager.getChildAt(0)
if (child is RecyclerView) {
child.overScrollMode = View.OVER_SCROLL_NEVER
}
Thanks.
Solution 5:[5]
Use android:overScrollMode="never"
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/infoViewPager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:overScrollMode="never"
app:layout_constraintBottom_toTopOf="@id/guideLine1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
/>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | TreyWurm |
| Solution 2 | Boken |
| Solution 3 | Ozzini |
| Solution 4 | Paulo Coutinho |
| Solution 5 | Mubarak Tahir |
