1:修改爵位进场很慢的情况
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
package com.xscm.moduleutil.widget
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.MotionEvent
|
||||
import androidx.viewpager.widget.ViewPager
|
||||
/**
|
||||
* 项目名称:羽声语音
|
||||
* 时间:2025/12/3 9:30
|
||||
* 用途:
|
||||
*/
|
||||
|
||||
|
||||
class CustomViewPager(context: Context, attrs: AttributeSet?) : ViewPager(context, attrs) {
|
||||
|
||||
private var initialX = 0f
|
||||
private var initialY = 0f
|
||||
|
||||
override fun onInterceptTouchEvent(ev: MotionEvent): Boolean {
|
||||
when (ev.action) {
|
||||
MotionEvent.ACTION_DOWN -> {
|
||||
// 记录初始触摸点
|
||||
initialX = ev.x
|
||||
initialY = ev.y
|
||||
parent.requestDisallowInterceptTouchEvent(true) // 请求父容器不要拦截事件
|
||||
}
|
||||
MotionEvent.ACTION_MOVE -> {
|
||||
val deltaX = Math.abs(ev.x - initialX)
|
||||
val deltaY = Math.abs(ev.y - initialY)
|
||||
|
||||
// 如果水平滑动距离大于垂直滑动距离,才认为是水平滑动,ViewPager才拦截事件
|
||||
if (deltaX > deltaY && deltaX > 30) { // 30是阈值,可以根据需要调整
|
||||
return super.onInterceptTouchEvent(ev)
|
||||
}
|
||||
// 否则,不拦截,让子视图处理
|
||||
parent.requestDisallowInterceptTouchEvent(true)
|
||||
return false
|
||||
}
|
||||
}
|
||||
return super.onInterceptTouchEvent(ev)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user