初始代码提交

This commit is contained in:
2026-01-14 10:36:27 +08:00
parent 600aa4dbb0
commit 196cacfe5a
268 changed files with 22545 additions and 2 deletions
@@ -0,0 +1,65 @@
package com.sw.inbound.view
import android.content.Context
import android.util.AttributeSet
import android.view.MotionEvent
import android.view.ViewConfiguration
import androidx.core.view.ViewCompat
import androidx.recyclerview.widget.RecyclerView
import kotlin.math.abs
class NestedRecyclerView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : RecyclerView(context, attrs, defStyleAttr) {
private var lastY = 0f
private var isDragging = false
private var touchSlop = ViewConfiguration.get(context).scaledTouchSlop
override fun onInterceptTouchEvent(e: MotionEvent): Boolean {
when (e.action) {
MotionEvent.ACTION_DOWN -> {
lastY = e.y
parent.requestDisallowInterceptTouchEvent(true)
}
MotionEvent.ACTION_MOVE -> {
val dy = e.y - lastY
if (!canScrollVertically(-1) && dy > 0) {
parent.requestDisallowInterceptTouchEvent(false)
return false
} else if (!canScrollVertically(1) && dy < 0) {
parent.requestDisallowInterceptTouchEvent(false)
return false
}
}
}
return super.onInterceptTouchEvent(e)
}
override fun onTouchEvent(e: MotionEvent): Boolean {
when (e.action) {
MotionEvent.ACTION_MOVE -> {
if (!isDragging && abs(e.y - lastY) > touchSlop) {
isDragging = true
}
}
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
isDragging = false
}
}
return super.onTouchEvent(e)
}
override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
when (ev.action) {
MotionEvent.ACTION_DOWN -> {
stopNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL)
}
}
return super.dispatchTouchEvent(ev)
}
}