我有一个代码:
val touchDownSource = BehaviorSubject.create<MotionEvent>()
val touchUpSource = BehaviorSubject.create<MotionEvent>()
RxView.touches(binding.containerOverlay)
.subscribe({ me ->
when (me.action) {
MotionEvent.ACTION_DOWN -> touchDownSource.onNext(me)
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> touchUpSource.onNext(me)
}
})
val zipper = BiFunction<MotionEvent, MotionEvent, Pair<MotionEvent, MotionEvent>>({ v1, v2 -> v1 to v2 })
Observable.zip(touchDownSource, touchUpSource , zipper)
.filter { Math.abs(it.first.toPoint().length() - it.second.toPoint().length()) < 50 }
.map { it.second.toPoint() }
.subscribe({ Utils.toast(this, "${it.x}--${it.y}") }, ErrLogger::e)
我有2个BehaviourSubject
并向他们发送MotionEvent
&#39; s - ACTION_UP
和ACTION_DOWN
。然后我将主题压缩为ACTION_UP
和ACTION_DOWN
。但我的zipper
双功能总是将2个相同的事件作为参数 - ACTION_UP
具有相同的哈希码和坐标。
我做错了什么?