Solve the problem of Viewpager automatic carousel speed
/** * Call timed task, start scrolling */private void Startscroll () {Mtimer = new Timer (); Mtimer.schedule (New TimerTask () {@Override public void Run () {((mainactivity) MC
Ontext). Runonuithread (New Runnable () {@Override public void run () {
int currentitem = Mhomeviewpager.getcurrentitem ();
if (CurrentItem = = Mhomeviewpager.getadapter (). GetCount ()-1) {CurrentItem = 0;
} else {currentitem++;
} mhomeviewpager.setcurrentitem (CurrentItem);
}
});
}}, 2000, 2000); }//Stop scrolling private void Stopscroll () {if (Mtimer! = null) {//removecallbacks method is to delete the specified runnable pair
Mtimer.cancel () to stop the thread object from running.
Mtimer = null; }
} @Override public void OnDestroy () {Super.ondestroy ();
Stop scrolling stopscroll () when page is destroyed;
}
In the development of a situation when the thinking is right but it took a long time to solve the bottom four tab switch, corresponding to four fragment, when the page switch fragment in the Viewpager page faster, the marker point is also increasing, I know I need to initialize when the interface Onresume. Workaround: Call the Viewpager display method in the Onhiddenchanged method to cancel the task before it is displayed, emptying all veiw in the marker point.