pull/37/head
kunfei 5 years ago
parent 08a2c5356a
commit 8c957d5861
  1. 41
      app/src/main/java/io/legado/app/ui/widget/recycler/RecyclerViewAtViewPager2.kt
  2. 2
      app/src/main/res/layout/fragment_books.xml

@ -0,0 +1,41 @@
package io.legado.app.ui.widget.recycler
import android.content.Context
import android.util.AttributeSet
import android.view.MotionEvent
import androidx.recyclerview.widget.RecyclerView
import kotlin.math.abs
class RecyclerViewAtViewPager2(context: Context, attrs: AttributeSet?) :
RecyclerView(context, attrs) {
private var startX: Int = 0
private var startY: Int = 0
override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
when (ev.action) {
MotionEvent.ACTION_DOWN -> {
startX = ev.x.toInt()
startY = ev.y.toInt()
parent.requestDisallowInterceptTouchEvent(true)
}
MotionEvent.ACTION_MOVE -> {
val endX = ev.x.toInt()
val endY = ev.y.toInt()
val disX = abs(endX - startX)
val disY = abs(endY - startY)
if (disX > disY) {
parent.requestDisallowInterceptTouchEvent(canScrollHorizontally(startX - endX))
} else {
parent.requestDisallowInterceptTouchEvent(canScrollVertically(startY - endY))
}
}
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> parent.requestDisallowInterceptTouchEvent(
false
)
}
return super.dispatchTouchEvent(ev)
}
}

@ -4,7 +4,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView <io.legado.app.ui.widget.recycler.RecyclerViewAtViewPager2
android:id="@+id/rv_bookshelf" android:id="@+id/rv_bookshelf"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" /> android:layout_height="match_parent" />

Loading…
Cancel
Save