Solve the problem of Viewpager automatic carousel speed Change

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.