Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
}
like image 728
Daniel Kim Avatar asked Jul 03 '19 23:07

Daniel Kim


2 Answers

Solution

binding.viewPager2.apply {
    adapter = vpAdapter
    orientation = ViewPager2.ORIENTATION_VERTICAL
    registerOnPageChangeCallback(pageChangeCallback)
    (getChildAt(0) as RecyclerView).overScrollMode = RecyclerView.OVER_SCROLL_NEVER
}
like image 92
Daniel Kim Avatar answered Sep 28 '22 08:09

Daniel Kim


In case anyone searching for a Java solution

View child = viewPager2.getChildAt(0);
if (child instanceof RecyclerView) {
    child.setOverScrollMode(View.OVER_SCROLL_NEVER);
}
like image 20
TreyWurm Avatar answered Sep 28 '22 09:09

TreyWurm