An example of ViewPager determining whether to mark left or right
Examples are as follows:
//Record the positionOffsetPixels value of the last slide private int lastValue = -1; private boolean isLeft = true; (new () { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { if (positionOffset != 0) { if (lastValue >= positionOffsetPixels) { //Swipe right isLeft = false; } else if (lastValue < positionOffsetPixels) { //Swipe left isLeft = true; } setIndiactorView(positionOffset,isLeft); } lastValue = positionOffsetPixels; } @Override public void onPageSelected(int position) { if (isLeft){ ("onPageScrolled","--->Stroke left"); }else { ("onPageScrolled","--->Stroke right"); } } @Override public void onPageScrollStateChanged(int state) { } });
The above example of whether to judge whether to mark left or right in ViewPager is all the content I have shared with you. I hope you can give you a reference and I hope you can support me more.
Related Articles
Sample code for Android Picasso using Gaussian fuzzing
This article mainly introduces the sample code of Android Picasso using Gaussian fuzzing. The editor thinks it is quite good. I will share it with you now and give you a reference. Let's take a look with the editor2017-10-10Android Custom Dot Indicator
This article mainly introduces Android custom dot indicator in detail. The sample code in the article is introduced in detail and has a certain reference value. Interested friends can refer to it.2021-06-06Solution to the problem of jumping when switching between Android emoji panel and soft keyboard
This article mainly introduces the solution to the problem of jumping when switching between Android emoji panel and soft keyboard. Friends who need it can refer to it.2017-08-08Analysis of the method of implementing picture tiling by Android programming
This article mainly introduces the method of Android programming to realize picture tiling. Based on specific examples, it summarizes and analyzes three common operation techniques for Android to realize picture tiling effect. Friends who need it can refer to it.2017-06-06Detailed explanation of Android String resource file insertion value instance
This article mainly introduces the relevant information about the detailed explanation of the Android String resource file insert value instance. Friends who need it can refer to it.2017-06-06Android Toast Custom Display Time
This article mainly introduces Android Toast custom display time in detail, which has certain reference value. Interested friends can refer to it.2018-08-08Android recyclerview implements drag-and-drop sorting and side-sliding deletion
This article mainly introduces in detail to Android recyclerview to implement drag-and-drop sorting and side-sliding deletion, which has certain reference value. Interested friends can refer to it.2017-02-02Basic Android tutorial: Start-up example
This article mainly introduces the Android startup example. After the program is automatically started, the broadcast function is implemented. Friends who need it can refer to it.2014-02-02Android simulation login comments CSDN implementation code
This article mainly introduces the Android simulation login comment CSDN implementation code, which can log in to post comments to the official website, which has certain reference value. Interested friends can refer to it.2016-11-11RecyclerView implements horizontal sliding code in Android
This article mainly introduces the relevant information on the horizontal sliding code of RecyclerView in Android. It is very good and has reference value. Friends who need it can refer to it.2016-07-07