Custom scrollable View within ScrollView - android

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?

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.

Related

How to prevent the touch event from view to another view?

If I have a scrollview and a subview.
in the subview I add a touch effect so that I can get the touch position.
but the scrollview will also receive the touch event.
how to prevent it?
if I touch the screen from top to bottom to the subview then the page will scroll.
You can use nested scroll view instead of scroll view to prevent touch events on it.

Disallow horizontal recyclerview to listen to vertical swipe gesture

My fragment view implements a touch listener to listen to various gestures but my horizontally fashioned recyclerview consumes any gesture performed over it.
Basically I want to listen to vertical swipe when performed over recyclerview but I never receive callback in fragment view's gesture detector.
I was able to get a workaround for it. I had to subclass ViewGroup and override onInterceptTouchEvent and handle things using MotionEvent.{action_type}. Then I replaced the fragment view's parent view group with this custom view group inside xml layout.
So in nutshell, if I detect it as a vertical swipe I return true in my onInterceptTouchEvent otherwise false. If its false, the touch event is passed onto the child views for handling. Works perfect.

Custom View: swipe inside of scroll view

I created a custom View with Canvas and made it interactivly with overwriteing onTouchEvent.
But my view is inside of a ScrollView. It losts the focus while i drag/swipe an item to the right side in my custom view and move my finger a little bit up or down. Then the ScrollView react and my view never get an ACTION_UP Event.
Is there a way to avoid that the scrollView-Parent scolls while i interact with my custom view?
You need ViewParent.requestDisallowInterceptTouchEvent
https://developer.android.com/reference/android/view/ViewParent#requestDisallowInterceptTouchEvent(boolean)
In your custom view, once it has detected the touch gesture is for it, call scrollview.requestDisallowInterceptTouchEvent(true). The scrollview will then ignore further events for the duration of the touch i.e. until it (the scrollview) receives an ACTION_UP or ACTION_CANCEL event.

Touch Listeners for Parent and Child Views

I have a HorizontalScrollView inside a ViewPager , I have disabled the ontouchevent of the view pager, but the problem is horizontal scroll view is disturbed by this. It doesn't work properly, only moves a little.
I just want to understand the touch listeners functionality , onInterceptTouchEvent and touchEvent of the parent and child view, what is the order their calling if i touch on a child view?
touchEvent is first be handled by child View , if it doesn't handle it ,which means return false,the parent view will handle it. But onIterceptTouchEvent is before touchEvent.

How to Handle TouchEvents for Child View(CustomView) in Parent View (ScrollView)?

In my app i am using ScrollView for scrolling the ImageView, and i will add one customview dynamically to that ScrollView overlay of ImageView, i have onTouch events for customview. after adding to the scroll view i am not able to use the touch listeners of customview, still scrollview was working on that.
how to stop the scrollview touch listeners, and how to enable our custom view touch listeners..
I suggest you not to go with ScrollView. Simply add your custom view in LinearLayout and implement OnGestureListener and then using GestureDetector you can able to listen all events(like onDown(),onFling(),onScroll(),onSingleTapUp(),onDown(),etc). You can sense scroll magnitudes and then by using scrollBy() method you can scroll your image(custom view). For more detilas you can refer following posts:
Smooth scrolling in Android

Categories

Resources