Modify the ViewPager switching animation effect, and change the viewpager switching Animation
For example, if we click the right button and want to move the view on the left to have a translation effect, the system will flash when switching with the default ViewPager. Why?
Because viewpager actually has a scrollview, you can use the reflection method to set its scroll time. The Code is as follows.
Main Code:
// Step 1:
LayoutInflater mInflater = (LayoutInflater) context. getSystemService (Context. LAYOUT_INFLATER_SERVICE); View view = mInflater. from (context ). inflate (R. layout. vw_personalcyclic gtarget_test, personalFileMain); MyCycTargetViewPager mVp = (MyCycTargetViewPager) view. findViewById (R. id. cyctarget_viewpager); try {// viePager translation animation event Field mField = ViewPager. class. getDeclaredField ("mScroller"); mField. setAccessible (true); MyScroller mScroller = new MyScroller (mVp. getContext (), new AccelerateInterpolator (); mField. set (mVp, mScroller);} catch (NoSuchFieldException e) {e. printStackTrace ();} catch (IllegalArgumentException e) {e. printStackTrace ();} catch (IllegalAccessException e) {e. printStackTrace ();}
// Step 2:
/***** @ Desc: ViewPager animation time * @ author: pangzf * @ date: august 13, 2014 6:00:05 */public class MyScroller extends Scroller {// set the translation time you need private int animTime = 500; public MyScroller (Context context) {super (context );} public MyScroller (Context context, Interpolator interpolator) {super (context, interpolator) ;}@ Override public void startScroll (int startX, int startY, int dx, int dy, int duration) {super. startScroll (startX, startY, dx, dy, animTime) ;}@ Override public void startScroll (int startX, int startY, int dx, int dy) {super. startScroll (startX, startY, dx, dy, animTime);} public void setmDuration (int animTime) {this. animTime = animTime ;}
You cannot use viewpager to slide left or right in our project. You can click link to disable the sliding left or right.
Click the right button:
How can I remove the ViewPager switching animation or custom switching animation?
Let's see if you want anything? Search.eoeandroid.com/..t?true=you can search again in the Forum. There will be new discoveries.
How to remove the Viewpager switching animation?
Now I have made an application. Viewpager is very tangled. I have four screens, and there is no problem with sliding left and right. However, from the first screen to the fourth screen, the screen will go through 2 or 3 in the middle, and the interface looks ugly, how can we not execute this animation and look forward to a solution.