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.
Related
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.
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.
I have a ListView inside a ScrollView. I know I can intercept the touch events using the onInterceptTouchEvent method in the ScrollView. But once the child, i.e. ListView, starts consuming the touch event, onInterceptTouchEvent is not call. My problem is how can I transfer the touch event back to parent(i.e. ScrollView) once the ListView scroll has reached top. I want the scroll to be in continuation.
Suppose I'm scrolling the ListView and have reached the top of the ListView I want the scroll to continue so that I can scroll the parent, i.e. ScrollView. How can I achieve this?
You can check whether you are at the top of the listview, then return false from the touch event.
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.
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