Mastering the Android Touch System
Why Stack Overflow recommends it
Stack Overflow users link it when answering questions about touch event delivery, such as dispatchTouchEvent, onInterceptTouchEvent, onTouchEvent and why a listener or parent view does or does not receive events.
Recommended by 8 people across 9 different months, 2014 to 2021.
What it is
Dave Smith of Double Encore and NewCircle gives an AnDevCon talk on how Android handles touch input. It covers the touch event framework, how events flow from the Activity through ViewGroups to Views, custom touch handling, and the system's built-in touch and gesture handlers.
What people said
Strong rec Bryan · 2016-09 · Stack Overflow · on “How to use ViewPager OnTouchListener with ImageView inside it which also has OnClickListener”
The reason your ImageView is stealing the MotionEvent callbacks from your ViewPager is because the OnTouchListener.onTouch() method of your ViewPager always returns false . This means it will not capture any new MotionEvent callbacks after another View (your ImageView ) returns true in the onTouchEvent() method. Any View that is "clickable" returns true for any MotionEvent , and setting an OnClickListener for a View makes it clickable. Now the immediate reaction might be to make the OnTouchListener.onTouch() method return true for some or all case statements. But this would either make the ViewPager intercept all MotionEvent callbacks, or not give you the functionality that you want. The cor
Strong rec Son Truong · 2020-12 · Stack Overflow · on “Why RecyclerView still scrolls even after custom OnTouchListener implemented?”
I know that return true means the touch event is consumed and false means the touch event should get passed to the next view in view hierarchy This is not true, the correct order when a View handle a touch event is: View.dispatchTouchEvent() will be called first Sends event to View.OnTouchListener.onTouch() if exits If not consumed, process View.onTouchEvent() In your case because your return false in View.OnTouchListener.onTouch() , it means you do not consume the event, so the event will be routed to View.onTouchEvent() of RecyclerView , which explains why the RecyclerView is still scrolling. Solution 1 Return true in View.onTouchListener.onTouch() to show that the RecyclerView will consum
Recommends seb · 2014-03 · Stack Overflow · on “Android: Difference between onInterceptTouchEvent and dispatchTouchEvent?”
Because this is the first result on Google. I want to share with you a great Talk by Dave Smith on [this video] and the slides are available here [LINK] . It gave me a good deep understanding about the Android Touch System: How the Activity handles touch: Activity.dispatchTouchEvent() Always first to be called Sends event to root view attached to Window onTouchEvent() Called if no views consume the event Always last to be called How the View handles touch: View.dispatchTouchEvent() Sends event to listener first, if exists View.OnTouchListener.onTouch() If not consumed, processes the touch itself View.onTouchEvent() How a ViewGroup handles touch: ViewGroup.dispatchTouchEvent() onInterceptTouchEven
Recommends Pavel Dudka · 2014-03 · Stack Overflow · on “Android onTouchEvent in a view class”
Tried to post the same answer, but was late for couple of seconds :) I would only add a link to the awesome explanation what is actually happening: [this video]
Recommends nhaarman · 2014-08 · Stack Overflow · on “onTouch() isn`t called, even when I Touch the screen?”
onTouch in Activity will almost never be called, except if none of the View s consume the touch event. Instead, if you really want your Activity to handle touch events, listen for touch events in onInterceptTouchEvent(MotionEvent) . An interesting talk on this: Mastering the Android touch system [this video] .
Recommends Pavel Dudka · 2015-01 · Stack Overflow · on “Android Screen Touch Action”
Since onTouchEvent is the last point of touch event traversal, it might not be called if one of the children has consumed touch event already (of if you returned false for MotionEvent.ACTION_DOWN event indicating that you are not interested in this gesture at all). For your problem I would rather use dispatchTouchEvent() instead of onTouchEvent() and track touches there. For more information I highly recommend getting yourself familiar with talk from Dave Smith [this video] about Android Touch System
Recommends Johann · 2015-05 · Stack Overflow · on “Detecting ACTION_UP / ACTION_DOWN when a ScrollView is swiped up/down”
It is already known that when you scroll or swipe a scrollview you will get a ACTION_CANCEL event. I need to know when the ACTION_UP and ACTION_DOWN events occur but ACTION_CANCEL will prevent ACTION_UP / ACTION_DOWN from being issued if you continuously swipe up and down. I tried implementing onInterceptTouchEvent and even used getActionMasked but neither solution worked. Is there someway to know when my scrollview has generated an ACTION_UP when the user releases their finger during swiping? UPDATE: I am apparently making some assumptions about how Android handles motion and touch events. I found the following video helpful that gives a good overview on Android's touch system and it even c
Recommends Farmaan Elahi · 2017-10 · Stack Overflow · on “How to create multiple sections of textviews using multiple touch?”
For this,You need to understand how touch event work in Android.It is a very broad topic.You need to have proper understanding of `MotionEvent` ,how and when they are triggered.I would recommend you to listen to this talk from Dave Smith on [this video]
Recommends Son Truong · 2020-11 · Stack Overflow · on “Swipe detection and Touch listener not working inside fragment”
In Android, a gesture is defined as the beginning of ACTION_DOWN and ending with ACTION_UP. If you want your view to receive a gesture, you MUST return true for ACTION_DOWN, otherwise, you will got nothing. Root cause override fun onDown(e: MotionEvent): Boolean { return false } Because in this callback, you return false, that means your view does not show interest to any gesture, it explains why all callback such as onFling(), onSwipeRight(), onSwipeLeft() is not called. Solution Return true for the ACTION_DOWN event. override fun onDown(e: MotionEvent): Boolean { return true } Here [this video] is a great article about the Android Touch System. Please take a look when you have time.
Recommends Maci · 2021-12 · Stack Overflow · on “How to prevent ScrollView from intercepting click/touch events of the view behind it?”
If your custom view's calling the requestDisallowInterceptTouchEvent (true) during it's onTouchEvent where the action was ACTION_DOWN then the scroll view and non of it's parent will intercept the touch event until you call the requestDisallowInterceptTouchEvent with false. You can learn more from this video: [this video]