'How can I improve sensitivity of ViewPager2?

I am using this at the moment.

fun ViewPager2.reduceDragSensitivity(f: Int = 4) {
    val recyclerViewField = ViewPager2::class.java.getDeclaredField("mRecyclerView")
    recyclerViewField.isAccessible = true
    val recyclerView = recyclerViewField.get(this) as RecyclerView

    val touchSlopField = RecyclerView::class.java.getDeclaredField("mTouchSlop")
    touchSlopField.isAccessible = true
    val touchSlop = touchSlopField.get(recyclerView) as Int
    touchSlopField.set(recyclerView, touchSlop * f)       // "8" was obtained experimentally
}

When I set it to reduceDragSensitivity(0). It improves the sensitivity. But the item is hard to click. If I set it to reduceDragSensitivity(1), the scrolling is very slow and heavy. I'd like to make it like reduceDragSensitivity(0.5), but touchSlopField.set only gets Int value. How can I make it possible?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source