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

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).

Related

How to include extra fragments onto a ViewPager, in Android?

I am currently using a ViewPager with a TabLayout, the ViewPager as of now consists of three separate fragments.
I would like to be able to switch to a fourth fragment using a button on one of the already present fragments.
However, I do not want the fourth fragment to be accessible through the usual ways (aka scrolling) without using the button to reach the fourth fragment. Similarly, I would like scrolling to be disabled when I am currently displaying my fourth fragment.
What would be the best way to do so?
The current hack that I can think of would be to create a hidden fragment within my main layout. I can then display it when the button is pressed while hiding the ViewPager at the same time.
Are there any better ways to do this?
Include your ViewPager in fragment and onClick make replace for the next fragment, and you can return to ViewPager`s fragment onBackPress.

Swiping in order to call another Activity in Android

I want to make something like transitions between ViewControllers in iOS 7 but in Android, is it possible?
Explanation: please look at image below, I have main Activity which has ViewPager inside, so we can swipe between Fragments. I want to call another Activity (or Fragment) from each Fragment (blue on image) swiping to bottom or to top but this action should be done smoothly like in ViewPager.
You can intercept swipe up and down gestures and set items in viewpager accordingly. Please read this guide on how to intercept swipes in various directions.

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:

How to freeze and invert animation in ViewPager?

During a swipe from View A to View B, when the user releases in the ViewPager
- I would like the ViewPager to freeze at the current point and to animate back, to View A.
How should I implement that?
I have never done that before, but my guess would be to create your own CustomViewPager and make it do the new features for you.
This is the link to the method of the ViewPager that handles which page is to be displayed next.
I would try to add some kind of delay here for your freeze-effect and tweak the float-values which trigger whether you successfully swipe or pop back.

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