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.
Related
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.
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.
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.
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