简体   繁体   中英

Android: onInterceptTouchEvent() never receives ACTION_UP (despite never returning true!!!)

I have a RelativeLayout which contains a ListView .

When I scroll the listview up and down, I experience this on the RelativeLayout's onInterceptTouchEvent() :

  • the ACTION_DOWN is fired
  • only the first 5-6 ACTION_MOVE are fired
  • the ACTION_UP is never fired

Please note:

  • I am not implementing any onTouchEvent(), neither on the RelativeLayout nor on the ListView
  • I am only subclassing the RelativeLayout, implementing onInterceptTouchEvent(), which always returns false

Can anyone give an explanation for this?

===

This is the simple layout I am using:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ListView android:id="@+id/listview"
       android:layout_alignParentTop="true"
       android:layout_width="match_parent"
       android:layout_height="wrap_content" />

</RelativeLayout>

If I understand correctly, you want the RelativeLayout to receive the ACTION_UP event. A viewgroup (RelativeLayout) won't receive future touch events unless it expresses interest in the first touch events by returning true - so you should return true from onInterceptTouchEvent, not false.

Dave Smith explains it well here: http://www.doubleencore.com/2014/01/dave-smiths-talk-from-andevcon-2013-android-touch/

Summary: Return true, not false. And watch that video for a much better explanation :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM