Skip to content

Smooth Vertical View Pager by copying and tweaking android's ViewPager and then using it to make it vertical

Notifications You must be signed in to change notification settings

deepakmishra/verticalviewpager

Repository files navigation

VerticalViewPager

Scroll Preview

This is a VerticalViewPager implementation for Android. It extends the default Android ViewPager to support very smooth vertical scrolling instead of horizontal scrolling. To implement this the inbuilt ViewPager should be excluded from your project.

Note: The master branch follows v26.1.0. For v27.1.1, go to branch version27.

Implementation

Add the following lines inside the dependencies part of your build.gradle file to exclude the default Android ViewPager from your project

dependencies {
	configurations {
		all*.exclude module: "support-core-ui"
	}
}

Now copy the files from the android/support/v4 folder of support-core-ui v26.1.0 in this projects java folder and add them to you personal project's java folder. This should be done to supplement the code that was excluded above.

Also copy the VerticalViewPager file from this project's com/viewpager folder and add it to your project.

While adding a ViewPager to your layout xml file, add the new VerticalViewPager that you included from this project instead of the default Android ViewPager, like this :

<com.viewpager.VerticalViewPager
	android:id="@+id/view_pager"
	android:layout_width="match_parent"
	android:layout_height="match_parent" />

While adding a reference to the VerticalViewPager to your java file, you may use it the same way you would use a normal ViewPager, like this: ViewPager viewPager = findViewById(R.id.view_pager);

Understanding

The ViewPager used in this project is the default Android ViewPager and it is kept effectively the same as before. Only some of the values are extracted as instance variables so that they can be changed through reflection.

For example, in the onInterceptTouchEvent method, the instance variable minYXRatioForIntercept has been added to the ViewPager file so that it can be easily modified through reflection.

minYXRatioForIntercept can be modified to change the minimum swipe distance required to move the page up or down.

Similarly, in the onTouchEvent method, the instance variable minYXRatioForTouch has been added to the ViewPager file so that it can be easily modified through reflection.

In the VerticalViewPager file in this project, we swap the values of x and y in the onInterceptTouchEvent and onTouchEvent methods, and edit the required values through reflection in the init method.

Contributors

Deepak Mishra

Denver Braganza

About

Smooth Vertical View Pager by copying and tweaking android's ViewPager and then using it to make it vertical

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages