Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 识别被触摸的视图_Android_Kotlin - Fatal编程技术网

Android 识别被触摸的视图

Android 识别被触摸的视图,android,kotlin,Android,Kotlin,我有一个布局,看起来像这样: <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http:/

我有一个布局,看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/main_read_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.project.books.flipview.FlipView
        android:id="@+id/flip_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/color_black"
        app:orientation="horizontal"
        tools:context=".ReadActivity" >
    </com.project.books.flipview.FlipView>

    <include
        android:id="@+id/readingtoolbar"
        android:visibility="invisible"
        app:layout_constraintBottom_toBottomOf="parent"
        layout="@layout/readingbar_layout" />

</android.support.constraint.ConstraintLayout>
所以工具栏会滑出,但如果我点击工具栏上的任何蜡笔,它会滑回原来不该滑的地方。基本上,我想要的是,如果用户单击工具栏本身以外的任何地方,那么它应该向下滑动

我尝试使用onTouch来传递视图,而不是dispatchTouchEvent,但即使使用相同的逻辑,我似乎也无法捕获点击。不过,我可以捕获一个拖动事件

class ReadActivity : Activity(), FlipViewAdapter.Callback, FlipView.OnFlipListener, FlipView.OnOverFlipListener, View.OnTouchListener {
...
}
背景

flip_view.setOnTouchListener(this)
正在测试“单击此处”

override fun onTouch(v: View?, ev: MotionEvent?): Boolean {
    println("clicking")
    // put actual clicking logic
    return true
}

工具栏组件是否有单击事件,或者工具栏是否有xml中定义的android:clickable=“true”?是的,它有单击事件,但没有android:clickable=“true”。我用工具栏布局更新了这个问题。因此,尝试向工具栏添加
android:clickable=“true”
,看看它是否使用触摸事件,此外,您应该为蜡笔栏创建一个新的自定义布局,不要用
Toolbar
来包装它,因为我认为
Toolbar
不是为那种目的而设计的。不幸的是,它不起作用。单击工具栏本身时仍然会上下滑动。在
活动中,您在哪里定义
dispatchTouchEvent
flip_view.setOnTouchListener(this)
override fun onTouch(v: View?, ev: MotionEvent?): Boolean {
    println("clicking")
    // put actual clicking logic
    return true
}