RxAndroid - 使用 RxView.touches 清除其他处理程序

RxAndroid - using RxView.touches clears other handlers

我正在尝试将触摸处理程序添加到 FabricView,但似乎这样做我无法再绘制草图了。事实上,FabricView 本身定义了一个 Touch 处理程序,但似乎我的尝试 - 使用 RxAndroid2 - 清除了预定义的处理程序,而不是链接到它。

我希望能够使用我的处理程序,而无需清除现有处理程序。

这是我主要的一部分activity(sketchview 是 FabricView 的一个实例)

sketchView.backgroundMode = FabricView.BACKGROUND_STYLE_NOTEBOOK_PAPER
    RxView.touches(sketchView, {_ -> true}).subscribe { // setting to false let me sketch, but I don't get any toast
        event -> when(event.action){
            MotionEvent.ACTION_DOWN -> {
                toast("Starting")
            }
            MotionEvent.ACTION_UP -> {
                toast("Stopping")
            }
            else -> {}
        }
    }

这是我的 app.gradle 的摘录:

compile 'com.github.antwankakki:FabricView:latest'
compile 'com.rmtheis:tess-two:7.0.0'
compile "io.reactivex.rxjava2:rxjava:2.1.0"
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
compile 'com.jakewharton.rxbinding2:rxbinding:2.0.0'
compile "org.jetbrains.anko:anko-commons:$anko_version"

为了使用 FabricView,我们必须在根 gradle 构建的 allProjects 部分包含 JitPack。

allprojects {
    repositories {
        jcenter()
        maven { url 'https://maven.google.com' }
        mavenCentral()
        maven { url "https://jitpack.io" }
    }
}

这是the page of the FabricView source code

RxView.touches() return你有一个 ViewTouchObservable 调用 view.setOnTouchListener(listener) 订阅来观察触摸事件。

Warning: The created observable uses View.setOnTouchListener() to observe touches. Only one observable can be used for a view at a time.

像这样将触摸事件绝对绑定到此可观察对象。它 returns true 因此 onTouchEvent() 不会被调用。要同时使用这两种行为,您可能需要稍微重写 ViewTouchObservable 和 return false