viewpager2를 카드뷰처럼 넘기고 싶은데 너무 휙휙 돌아가지는 거 같아서 서치하다 찾은 방법이다
ViewPager2는 ViewPager와 다르게 RecyclerView를 기반이라 recyclerview내에 스크롤 감도를 조절하는 mTouchSlop을 변경하면 된다
fun ViewPager2.reduceDragSensitivity() {
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 * 8) // 원하는 숫자
}
touchSlop 값은 유저가 스와이프할 때 인식되는 최소 거리라, 값을 높일수록 드래그 감도가 낮아진다고 생각하면 된다
하지만 이 방법은 내부 필드에 접근 하는 방법이라 업데이트가 된다면..! 안 먹히는 방법이 될 수도 있다 ..!
'📱 Android' 카테고리의 다른 글
[Android] AAC의 LiveData, ViewModel의 LiveData (0) | 2025.02.04 |
---|---|
[Android] binding 즉시 업데이트 하기 executePendingBindings (0) | 2024.11.21 |
[Android] 이미지뷰에 apng 파일 적용하기 (0) | 2024.11.17 |
[Android] Multipart / Presigned url (0) | 2024.11.14 |
[Android] 앱 배포 실패, 그 원인은 SoLoader ? (ft.giphy) (4) | 2024.10.11 |