自动滚动查看具有少量间隔的分页器页面

时间:2013-12-12 11:15:21

标签: android timer android-viewpager timertask

我已经使用android视图寻呼机来显示图像和文本现在我想要的是在几秒钟后用动画滚动页面?

它的作品,但不是smothly viewpager页面滚动。

定时器调用

  mCountDownTimer = new MyCountDownTimer(4000, 1000);
  mCountDownTimer.start();

 private static MyCountDownTimer mCountDownTimer;
  private class MyCountDownTimer extends CountDownTimer {
    public MyCountDownTimer(long startTime, long interval) {
        super(startTime, interval);
    }

    @Override
    public void onFinish() {
        System.out.println("Time's up!");
        startTimerWithAnim();
    }

    @Override
    public void onTick(long millisUntilFinished) {
        System.out.println("mill="+millisUntilFinished / 1000);
    }
}

如果'MyCountDownTimer'调用那么'startTimerWithAnim'方法调用

      public static void startTimerWithAnim() {
       if (mCountDownTimer != null)
          mCountDownTimer.cancel();
        mHandler = new Handler();
        mRunnable = new Runnable() {
          public void run() {
              if (mMemberPagerAdapterList != null) {
                  if (mPagedGrid.getCurrentItem() == mMemberPagerAdapterList.getCount() - 1)
                    mPagedGrid.setCurrentItem(0, true);
                else if (isFirstTimeCurrentItem) {
                    mPagedGrid.setCurrentItem(0, true);
                    isFirstTimeCurrentItem = false;
                } else if (isFirstTimeCurrentItem == false)
                    mPagedGrid.setCurrentItem(mPagedGrid.getCurrentItem() + 1, true);
            }
        }
    };

    mTimer = new Timer();
    mTimer.schedule(new TimerTask() {

        @Override
        public void run() {
            mHandler.post(mRunnable);
        }
    }, 100, 4000);
}

2 个答案:

答案 0 :(得分:0)

你去吧!

  class UpdateTimeTask extends TimerTask {
                       public void run() {
                           viewPager1.post(new Runnable() {
                                public void run() {

                                    if(viewPager1.getCurrentItem()<i){
                                    viewPager1.setCurrentItem(viewPager1.getCurrentItem()+1,true);
                                    String abc = String.valueOf(viewPager1.getCurrentItem());
                                    Log.i("timer_+",abc);
                                    }
                                    else
                                    {
                                        viewPager1.setCurrentItem(0,true);
                                    }
                                } 
                            });
                      }
                     }

                    Timer timer = new Timer();
                     timer.schedule(new UpdateTimeTask(), 2000, 4000);

答案 1 :(得分:0)

function doSomething() {
  $(document).scrollTop($(document).height());
}
setInterval(doSomething, 5000);

这将每5秒滚动到页面底部。如果您在用户向下滚动时(如Facebook)有自动加载内容,这将非常有用。