ViewPager in a ListView - how to lock the scrolling axis? - android

I have a ViewPager widget in every row of a ListView. This provides a shelf-like UI, so the user can scroll around searching for a shelf vertically, and then scroll horizontally amongst the contents of a shelf. This works.
But the scrolling experience is terrible: if I start to drag a shelf's ViewPager, scroll it horizontally, and accidentally drag a bit upwards/downwards, then the ListView "traps" this dragging action, and start to scroll vertically, ending my horizontal drag. In this state, the drag action won't "return" to the ViewPager, the ListView has it, and that's it. I have to start another drag action to affect the ViewPager again. So I guess the ListView has precedence in these cases.
How can this be fixed? I'd like to achieve the exact opposite: If the ViewPager inside a list row starts reacting to a horizontal drag, then it should trap that action, and this drag should stop affecting the ListView, no matter how the user moves his/her finger vertically. Can this be done?

I've found a solution in this thread. There the problem is to handle touch events properly for a HorizontalScrollView inside a regular ScrollView, but the solution to that problem seems to apply to this one too.

Related

Conflict between recyclerview scroll and viewpager swipe

In my app I have a ViewPager that has four fragments. All the fragments are composed of RecyclerView which can be scrolled vertically. My problem is that when I try to navigate to other fragments and swipe left or right, the RecyclerView's scroll is detected first (mostly) and instead of going to other fragments the RecyclerView gets scrolled.
To be more clear, if I scroll the recyclerView, then suddenly swipe left or right, the viewpager never swipes.
What should I do?
When you scroll your RecyclerView vertically and cross a threshold to trigger scrolling, it consumes the TouchEvent. This means the default behavior is until you release your finger from the screen, the ViewPager will not be able to trigger a horizontal scroll. This is default behavior for how scrolling views interact with each other. You could attempt to override touch handling by extending RecyclerView and ViewPager or having a coordinating view that dispatches all TouchEvents to both views. However, either of these approaches could present a number of issues.
If you were to look at the Play Store for reference, its touch handling works the same as what you are seeing here.

How to Intercept touch events in nested RecyclerViews to avoid propagation to parent?

I have a complex layout made of a ViewPager with 3 (horizontal) fragments [PAGE].
Each PAGE is made of several (vertical) RecyclerView [CARD].
Each CARD, has a an (horizontal) RecyclerView with several items.
My problem is that, when swiping between the items, the touch event is ofter propagated to the viewPager, resulting in an unwanted page change.
Is there a way to block, when touching a specific area of the screen (i.e. All the area covered by the most inner RecyclerView) the propagation of the touch event, EVEN if no element is touched (there is free space bewteen items, and touching there cause the unwanted page change)
http://i.stack.imgur.com/8vfAI.jpg
Here there is my example, when swiping on the Scrollable Area, I do not want to be able to move to other pages.
Thanks for the help
Example of layout
If your CARD has a custom RecyclerView (for the horizontal recycler), you could call requestDisallowInterceptTouchEvent() on touch events.
This would have the parent RecyclerView as well as the ViewPager stop receiving inputs until the horizontal Recycler stops receiving touch events (the call cleans up itself if I remember right).

Android RecyclerView Custom Stacking Scroll

So i have this requirement for a custom scroll for a linear layout and i have no idea where to start. The scroll will be like this:
instead of recyclerView items leave the screen, the top most item will remain fixed, and the items will overlap it when scrolled. So instead of scrolling out of the screen, or scrolling into the screen, they will scroll out from the first card and into the first car.
I would seek for advices with alternatives, as i have relatively short time to do it. I would avoid doing a custom layout manager unless really necessary (its tricky to do so).

How to create an infinite carousel horizontal scroll bar in android?

In my android app, I have a horizontal scroll bar, and I can scroll all the way to the left and right. Go too far and you can't scroll anymore.
How can I change it that, you can keep scrolling left or right for as long as you want. Basically when u see the last thing in the horizontal scroll, then if you keep scrolling, you see the first item, and it loops like this. Similarly if you scroll to the left after seeing the first item, you see the last item.
Is this possible to do in android?
Thanks

Animating a View while ListView is scrolling not working

I'm trying to achieve the effect that the Google+ Android app has where there is a View that sits at the bottom of the screen, and when the user scrolls the ListView that sits behind it UP the View animates down, off screen. When the user scrolls the ListView down, even slightly, the View animates back up, on screen.
I've set up a GestureDetector, that is giving me callbacks for the scroll event on my ListView, and the callbacks are constant as I scroll so I know that part is working.
In my callback I'm trying to use the ViewPropertyAnimator to animate my y value as such:
headerView.animate().yBy(distanceY).start();
Nothing happens until I stop scrolling. Is there any way to throw this animation in with the ListView scroll on the UI thread? I get the feeling it's waiting.
I've been fighting this one also. The trick I ended up using was to replace
headerView.animate().yBy(distanceY).start();
with
headerView.setTranslationY(floatValue);
Hope this helps!

Categories

Resources