Foreword: The owner said that the viewpager of android project is not sensitive and needs a long sliding distance to turn the page. It is required to shorten the sliding distance and turn the page in a shorter distance.
This thing is really not easy to do. I checked a lot of information on the Internet and tried a lot of methods. Until the following article was reproduced, it solved my problem. Note that the source code of the viewpager needs to be modified, that is to say, the source code of the viewpager should be copied to the project for modification. (The source code of PageAdapter is also copied).
Kind testing, effective!!
From: http://blog.csdn.net/focuman/article/details/37528039
I've never had any big problems with ViewPager before, and it works well. Recently, in the company's new generation products (hardware products, resolution 2560*1440), ViewPager control is widely used for high resolution and horizontal screen application development, but the problem arises. In the process of turning pages, it needs to slide more than half of the resolution of the screen (2560/2=1280) to turn pages, which greatly affects the user experience.
First, the application scenario is briefly introduced.
1. Hardware: The company develops independently, the touch screen uses infrared (so the touch effect is not as smooth as the capacitive screen), and the display screen uses high-definition 2K display screen.
2. Software System: Android 4.2.2
Companies need to customize their own software for users to use. For the ViewPager control, Android Engineers never know how to deal with this problem. There are only two ways: 1. Customizing controls and 2. Modifying ViewPager. Today, I went to the source code of ViewPager, and finally found the point where I could change the problem. The following is the main point of view Pager's source code: ViewPager's source code, ViewPager's source code, ViewPager's source code, ViewPager's source code, View
The determineTargetPage method calculates which page to slide to next. This method call is based on the event MotionEvent.ACTION_UP. Let's start with the meaning of the parameter:
CurrtPage: The page currently displayed by ViewPager
Page Offset: Page offset for user sliding
velocity: Sliding rate
DeltaX: The Distance of X-Direction Moving
After debug the release, the problem was found in the parameters of 0.4f and 0.6f. It is concluded that 0.6f represents the offset that users can turn pages when sliding, so it is not difficult to understand why they should slide half screen or more.
The modification method is as follows:
In this way, user sliding offset can be set and page can be switched, so as to solve the problem that the resolution of large screen sliding is not smooth.
If you have any questions, please ask me again. Thank you.