I have a vertical RecyclerView and inside every item a custom view with own horizontal scroll and scale. When I try to scroll view inside item I get scroll conflict RecyclerView interrupts touch event and tries to move the list.
How can I restrict RecyclerView to handle horizontal swipe event?
I tried to interrupt event via RecyclerView.OnItemTouchListener and pass them directly to my custom view. That almost works but sometimes I get wrong events and scroll in the custom view does not work.
Has someone else faced this problem?
Try use simple OnTouchListener instead OnItemTouchListener
Related
I have a RecyclerView (which scrolls vertically) whose ViewHolders contain RecyclerViews that scroll horizontally. When you tap on an item in horizontal (nested) RecyclerViews, I want the entire row to have the ripple effect.
To do this, I've been trying to override the touch events and get them to get passed up the view stack (by returning false in touch event handlers). This works on views other than RecyclerViews, but it isn't having the desired effect for RecyclerViews.
How do I correctly pass the tap event on a RecyclerView up to the enclosing view?
Haven't found a way to pass the click event up to a recycler view's parent view, but the important thing was getting the ripple effect to happen – which I was able to do. So when a view holder's itemView get's tapped, I do this:
val background = itemView.background
if (background is RippleDrawable) {
background.setState(intArrayOf(android.R.attr.state_pressed, android.R.attr.state_enabled))
}
Which manually triggers the ripple effect.
In my project I have RecyclerView with fast scroll and I need show some view only on fast scroll event (not for default scroll events). Is there some way to achieve this?
If you mean fling by fast scroll, then you can register a RecyclerView.OnFlingListener to your RecyclerView
Ref:
https://developer.android.com/reference/android/support/v7/widget/RecyclerView.OnFlingListener
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 listView, with a footer attached to it, which is Button. This Button works fine when there is no Scrolling involved.
When the listView is scrolling, it becomes unclickable, like the other items in the ListView. Since it takes some time after the View have reached bottom, and the View actually stops "Scrolling", the footer(Button) is unclickable for a sec or 2. Is it possible to make an item, in this case a ListView footer, clickable while the ListView is scrolling? Or another clever solution to this issue?
try to make the button.setClickable(true). it should be clickable during the scrolling
This sounds like another one of a very long list of problems with ListView stealing touch events from its child views. The solution is to use RecyclerView instead. ListView is essentially deprecated and RecyclerView is the replacement.
Simple question - how to disable recyclerview scrolling while swiping its item? I created OnTouchListener inside recyclerView item view holder, but it catches swipe events only if user makes straight horizontal line. Otherwise recycler list is scrolling. Any ideas?
I am not using ItemTouchHelper because it doesnt quite do what I want. I solved this by checking the source to it and finding the call to:
getParent().requestDisallowInterceptTouchEvent(true)
Call that when you determine the user has started swiping (i.e., moved more than a few pixels). Then don't forget it to call it again with false when the swipe is done.
I'm facing the opposite problem. If you are using the ItemTouchHelper, do this
mItemTouchHelper.startSwipe(myViewHolder);
This would force the swipe instead of the scroll.