I have a viewpager that includes one recycler view.
Every item of the recycler view can be dismissed by swipe.
When i apply the recycler view in the view pager, the view pager does not allow the swipe-to-dismiss and overlay the control with the page swapping.
When i detect the swipe in the recycler, i disable the viewpager onInterceptTouchEvent, but the swipe movement initiated previously is restarted.
Anyone has a solution ?
Using a swipe action on a recyclerview item works against the swiping action of a viewpager. Essentially, you're telling the user to do the same action on the same screen to do two entirely different actions. This is bad design. Ask yourself if it is necessary to use both of these things. I had the same predicament and removed the viewpager entirely.
Related
I am using coordinator layout with tabs, some of which (the tabs) contain a recycler view whilst some don't. All the tabs contain a floating action button. On scrolling the recycler view with the in one of the tabs, the floating action button is scrolled off by the coordinator layout. However, when I switch to the tab without the recycler view, and not being able to scroll, the tab remains scrolled off the screen (as it was done in the tab with a recycler).
How do I bring back the floating action button back when there is no way of scrolling in the tab without the recycler or any scroll mechanism?
Turned out to be a simply solution of translating the fab back in. floatingActionButton.setTranslationY(0.0f);
I have a ViewPager. Inside this ViewPager I have Fragments that have all the same layout. The layout contains a header and a RecyclerView and I want only the header of this layout to be swipeable. So the user may only switch between the fragments inside the viewpager when he is swipping on the header. I have tried a CustomViewPager but it was not working the way I wanted it to.
Does someone have a solution?
My dirty but working solution is to set a custom TouchListener to my header view and every time it detects a fling to the right or left I call setCurrentItem(index, true) with the ViewPager. It is not the optimal solution, but is working for now.
I am trying to scroll more than one item in a ViewPager per swipe. I have implemented a carousel like ViewPager by setting the PagerAdapter's getPageWidth() to return .33f. And I am trying to scroll 3 items per swipe. I have tried incrementing position in ViewPager.onPageScrolled(). But it isn't working.
ViewPager is not the answer. You need HorizontalScrollView with paging. that enables you when flinging to swipe multiple pages but doesnt stop in the middle of a page.
In case u still want ViewPager -
Read this
What i am doing is showing Fragment in view pager and has Gesture detector implemented on Whole view. When we touch the View i want to hide some layouts from current fragment and all other fragments in view pager.
But problem is this that view pager automatically generates next and previous view
and when i swipe to next view it does not hide those layouts but other Fragments other than its consecutive ones Layouts are Gone.
How do i refresh consecutive fragments of view pager from fragment itself.
Thanx in advance.
You should have an activity that control that ViewPager and detects what Fragments to display. That's the place to update the fragments.
Use the OnPageChangeListener listener and inform the fragment of the change.
If you want to do it from the Fragment itself, try onStart() or onResume()
Fragments can be notified of events, so they can take actions accordingly.
One way of doing this would be using a broadcast like in ViewPager Activity to notify a Fragment of a specific event
Other way is like #Antonio said, making it on the OnPageChangeListener (I suppose that would be a lot cleaner).
I have a layout with a ViewPager and also right left arrows inside the ViewPager for manually moving to the next view without swiping.
While the user is swiping, I'd like to hide those arrows (or maybe only show the right one when the user is swiping to the right...)
How can I find out if the user is scrolling a ViewPager?
Found the solution:
Method onPageScrollStateChanged from SimpleOnPageChangeListener
http://developer.android.com/reference/android/support/v4/view/ViewPager.SimpleOnPageChangeListener.html#onPageScrollStateChanged(int)
the state argument of onPageScrollStateChanged is 1 when you start draggin, 2 when you let go and 0 when the ViewPager has stopped scrolling