Android: Hide view while scrolling a ViewPager - android

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

Related

Scroll more than one item in ViewPager

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

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.

I want to dont change ViewPager pages when touching a specified view

I have a ViewPager with two pages. in page 1 is a chart with a movable pointer.
I want to when user changing the pointer location with touch, ViewPager pages dont change and stay on page 1.
best and simple way you first migrate viewpager to viewpager 2 and then just one line code you can disable swiping touch page
viewPager2.setUserInputEnabled(false);
and enable
viewPager2.setUserInputEnabled(enable);
Please check : Migrate from ViewPager to ViewPager2

[Android]How to disable page horizontal move along drag in ViewPager?

I have a ViewPager with a FragmentPageAdapter set for it.
And the ViewPager is show some simple fragment.
I am able to use ViewPager for swipe between fragments.
However, I don't like the scrolling effect of ViewPager that showing partial content of next fragment while swiping/dragging current fragment.
Instead, I would like to switch to next fragment at instant with swipe(but without scrolling effect) and show fragment immediately.
How can I do such thing(must use ViewPagger)?
You have to implement your own "SwipeDetector" and use mViewPager.setCurrentItem(index, false) method (second parameter indicates whether to enable animation or not).

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:

Categories

Resources