Scroll more than one item in ViewPager - android

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

Related

Android: ViewPager swipe only on particular View

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.

Horizontal Recyclerview inside Viewpager android

I am facing a problem with Recyclerview inside Viewpager fragments.
I have two fragments and both loaded in ViewpagerAdapter. In the second fragment, I have a simple Horizontal Recyclerview. Initially, 1st fragment is loaded in ViewPager and when I swipe right to left on screen it will redirect me to the second fragment.
In the second fragment Recyclerview already loaded. But when I tried to scroll Recyclerview horizontally for more items it is not scrolling it redirects me to the 1st fragment from swipe left to right.
How to allow the user to view more items?
Help me with this problem.
Thanks in advance.
Try to enable Nested Scrolling for recyclerview
after initialising your recyclerview, add this line of code
your_recyclerview.setNestedScrollingEnabled(true);

Swipe in Recycler when applied in ViewPager

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.

Sync two ViewPagers inside a Vertical ViewPager

I have an activity. Inside that activity I have implemented VerticalViewPager in which 3 pages are fed i.e. Upper Page, Middle page and Lower Page. Inside the middle page fragment and Lower page fragment I have separately another ViewPagers(Horizontal).Inside these ViewPagers I have 3/3 pages each. So far I have been able to make them working just fine i.e. on vertical swipe gesture the VerticalViewPager gets triggered and on horizontal swipe gesture native android ViewPager gets triggered. Now I need to sync the horizontal swipe transition between the middle fragment pages and lower fragment pages.
Let me give an example: say I have A,B and C pages inside middle fragment of VerticalViewPager and D,E,F inside the lower vertical fragment. Assume I am in the middle fragment now. So when I swipe from A to B left to right, the lower fragment should also swipe from D to E automatically.
[P.S.: For the horizontal(native) ViewPager to work inside
VerticalViewPager, the horizontal ViewPager Adapter needs to run
in the AsyncTask or threads. So please consider this scenario as
well]
You can make the adapter scope available globally and set the current view or fragment according to the change in the middle fragment.
According to the example:

Android: Hide view while scrolling a ViewPager

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

Categories

Resources