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 = 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) {super (context );} public myscroller (context, 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: