Reputation: 929
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
}
Upvotes: 24
Views: 8498
Reputation: 53
In Java you can simply do it like this
viewpager2.getChildAt(0).setOverScrollMode(RecyclerView.OVER_SCROLL_NEVER);
Upvotes: 2
Reputation: 207
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"
/>
Upvotes: -1
Reputation: 5362
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()
Upvotes: 5
Reputation: 705
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.
Upvotes: 0
Reputation: 145
This one worked for me:
val child = binding.<your viewPager camelCase id>.getChildAt(0)
(child as? RecyclerView)?.overScrollMode = View.OVER_SCROLL_NEVER
Upvotes: 0
Reputation: 564
In case anyone searching for a Java solution
View child = viewPager2.getChildAt(0);
if (child instanceof RecyclerView) {
child.setOverScrollMode(View.OVER_SCROLL_NEVER);
}
Upvotes: 15
Reputation: 929
Solution
binding.viewPager2.apply {
adapter = vpAdapter
orientation = ViewPager2.ORIENTATION_VERTICAL
registerOnPageChangeCallback(pageChangeCallback)
(getChildAt(0) as RecyclerView).overScrollMode = RecyclerView.OVER_SCROLL_NEVER
}
Upvotes: 47