Почему мой пользовательский constraintLayout перехватывает событие касания (свайп), только если касание начинается в дочернем представлении с установленным onClickListener?
open class Mywordd @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null ) : ConstraintLayout(context,attrs) {
var initialTouchPoint = Point(0, 0)
var mosso=0.0f
val mTouchSlop: Int = ViewConfiguration.get(context).scaledTouchSlop
override fun onInterceptTouchEvent(event: MotionEvent): Boolean {
val action = event.actionMasked
val currentPoint = Point(event.x.toInt(), event.y.toInt())
if (action == MotionEvent.ACTION_DOWN) {
// mark the beginning, when finger touched down
initialTouchPoint = Point(currentPoint)
} else if (action == MotionEvent.ACTION_UP) {
// reset the marking, when finger is lifted up
initialTouchPoint = Point(0, 0)
}
else if (action== MotionEvent.ACTION_MOVE){
val diffX = currentPoint.y - initialTouchPoint.y
val diffY = currentPoint.x - initialTouchPoint.x
println("$stoswippando $mosso")
if(stoswippando==-2) {
mosso=diffY.toFloat()
return true}
if (Math.abs(diffY) > Math.abs(diffX)) {
if (Math.abs(diffY) > mTouchSlop && Math.abs(diffY) / 2 >Math.abs(diffX) ) {
mosso=diffY.toFloat()
stoswippando=-2
return true
}
}
}
mosso=0.0f
return false
}
var fistetim= 1
override fun onTouchEvent(event: MotionEvent): Boolean {
val action = event.actionMasked
if(action== MotionEvent.ACTION_MOVE &&mosso!=0f) { this.animate().translationX(mosso*2.toFloat())
if(mosso<0) {
if(fistetim!=0){
fistetim=0
}}
else {
if(fistetim!=-1){
fistetim=-1
}}
}
if(action== MotionEvent.ACTION_UP &&mosso>0){
if(mosso>16){
println("starto etimo")
}
this.animate().translationX(0f).withEndAction { stoswippando=0 }
fistetim= 1
}
if(action== MotionEvent.ACTION_UP &&mosso<0) {
if(mosso<16){
println("mosso<16")
}
this.animate().translationX(0f).withEndAction { stoswippando=0 }
fistetim= 1
}
return true
}