OnTouch返回false但事件仍然消耗

时间:2016-06-26 13:39:33

标签: java android user-interface

类似帖子:Returning false in OnTouch on ImageView but still event is getting consumed

基本上,我在OnTouchCardViewRelative Layout上注册了Recycler View个侦听器,并使用以下XML为所有方法返回false

 <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view_list_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardUseCompatPadding="true">

<RelativeLayout
    android:id="@+id/relativelayout_list_item_text_memo"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/yellow">



        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_view_photos_memo"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:foregroundGravity="center"
            android:orientation="horizontal"
            android:scrollbars="vertical"/>
   </RelativeLayout>
   </android.support.v7.widget.CardView>

根据我的理解,如果OnTouch方法返回false,则将调用兄弟/父视图处理程序方法。奇怪的是当我点击RecyclerView的区域时,尽管返回值为false,但OnTouch的{​​{1}}侦听器处理程序仍会被调用。但是,如果我点击RecyclerView之外的RelativeLayout区域,它会按照惯例运行(它调用RecyclerView的{​​{1}}并打印日志信息)。 从我上面链接的帖子中,有些用户显然认为这是Android中的一个错误。它是真的如此,还是我错过了什么?

编辑:这是我项目中唯一的监听器实现。以下代码位于适配器支架内(特别是支架的构造方法内)与适配器分开的类:

onTouch

0 个答案:

没有答案