Custom scrollable View within ScrollView

2019-09-18 16:00发布

问题:

I created a custom View that implements a GestureListener and all the necessary logic to allow for some scrolling within the View. It works fine, as long as I do not put the View into some other scrollable View, e.g., a ScrollView.

If I wrap my View with a ScrollView, the touch events seem to be consumed by the ScrollView completely and are not handed through to my custom View. How can I tell the ScrollView that it should only consume touch events, if the touching happens outside of one of its children?

回答1:

You can request your scrollable container to not intercept touch events from your View by calling requestDisallowInterceptTouchEvent(true) on it when you receive an ACTION_DOWN event on your View.