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.
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.
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 got a Recyclerview and a EditText in my layout.
When I click outside the EditText (i.e clicks on the Recyclerview) I want the Recyclerview to get focus and the EditText view to loose focus. I cant get this to work. If I put a empty FrameLayout above the Recyclerview everything works as expected but I cant scroll the Recyclerview. Why cant I set the Recyclerview to be clickable and focusable?
I set these attributes in my layout xml
android:clickable="true"
android:focusable="auto"
android:focusableInTouchMode="true"
android:focusedByDefault="true"
on my Recyclerview/FrameLayout.
The reason your xml tags have no effect is how Android handles clicks. Every event goes through the view hierarchy of the layout. First, the very top level parent of the layout receives the event. If the top level layout does not handle the event, then it gets passed to the child under it and so on.
In your case the touch event is first sent to the FrameLayout and since it is handled, the event doesn't reach the RecyclerView and therefore you cannot scroll.
The correct way to handle touch is to set onTouchListener on both the RecyclerView and the child view. The onTouch on the RecyclerView is called first. You handle all your analyzing there (you can check x and y and also see if the touch falls inside a child view. you can also change the focus of each view dynamically).
If you don't want the child to also handle the touch return true;. Otherwise return false; and the touch event will trigger the onTouchListener of the child view.
I have a ScrollView, inside that I have LinearLayout with 4 children. My problem is that my ScrollView consumes events and because of that I am not able to long press on my child views. I tried setting setLongClickable(false) but it is of no use, if I intercept touch events I'm not able to scroll my ScrollView.
Normally Android uses a long press to begin a drag in cases like these since it helps disambiguate when the user intends to longPress an item vs. scroll the item's container. But if you have an unambiguous signal when the user begins longpress an item, try getParent().requestDisallowInterceptTouchEvent(true) from the view when you know the user is beginning a press. This will prevent the ScrollView from intercepting touch events until the end of the current gesture.(check this link https://developer.android.com/reference/android/view/ViewParent.html#requestDisallowInterceptTouchEvent%28boolean%29)
I have a ListView in which every row contains the following
-2 images
-1 textview
-1 scrollview that will display a bunch of tags
I searched the internet and I found out that is really hard to dispatch the scroll event from a listview to it's children, especially when they scroll on the same axis.
I was thinking if there is a possibility to find out if the touch event was on the scrollview and if it is, then I should dispatch the scroll event, else I will scroll the list.
Do you have any ideas how can I implement that?
EDIT:
I tried to to override the onTouchEvent method from the ListView but It doesn't work. When I drag over the scroll view the content disappears and when I scroll the listview, the content of the scroll view remains smudged on the screen.
Any ideas?