diff --git a/app/src/main/java/io/legado/app/ui/widget/RecyclerViewAtViewPager2.kt b/app/src/main/java/io/legado/app/ui/widget/RecyclerViewAtViewPager2.kt new file mode 100644 index 000000000..10abec353 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/widget/RecyclerViewAtViewPager2.kt @@ -0,0 +1,40 @@ +package io.legado.app.ui.widget + +import android.content.Context +import androidx.recyclerview.widget.RecyclerView +import android.util.AttributeSet +import android.view.MotionEvent +import kotlin.math.abs + +class RecyclerViewAtViewPager2 : RecyclerView { + constructor(context: Context) : super(context) + constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) + constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) + + private var startX = 0 + private var startY = 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) { + if (disX > 50) { + parent.requestDisallowInterceptTouchEvent(false) + } + } else { + parent.requestDisallowInterceptTouchEvent(true) + } + } + MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> parent.requestDisallowInterceptTouchEvent(false) + } + return super.dispatchTouchEvent(ev) + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_books.xml b/app/src/main/res/layout/fragment_books.xml index 8da85f913..1e2fbe64b 100644 --- a/app/src/main/res/layout/fragment_books.xml +++ b/app/src/main/res/layout/fragment_books.xml @@ -9,7 +9,7 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - - - -