【问题标题】:Android Imageswitcher: switch images periodically?Android Imageswitcher:定期切换图像?
【发布时间】:2012-06-13 12:22:18
【问题描述】:

我正在使用带有 TouchListener 的 ImageSwitcher 来更改数组中的图像。它工作正常,但我希望它每隔 x 秒左右切换一次图像,以便我可以添加 imageSwitcher.setImageResource(imageList[curIndex]); 到它。

有什么建议吗?

【问题讨论】:

    标签: android loops timer imageswitcher


    【解决方案1】:

    试试这个,

     imageSwitcher.postDelayed(new Runnable() {
                int i = 0;
                public void run() {
                    imageSwitcher.setImageResource(
                        i++ % 2 == 0 ?
                            R.drawable.image1 :
                            R.drawable.mage2);
                    imageSwitcher.postDelayed(this, 1000);
                }
            }, 1000);
    

    【讨论】:

      【解决方案2】:

      我认为可以通过 TimerTask 和 Timer。请尝试此代码。我认为它对你有帮助。

          private Handler mHandler;
          private Runnable mUpdateResults;
               private Timer timerAnimate;
              private TimerTask timerTask;
              mHandler = new Handler();
              mUpdateResults = new Runnable() {
                  public void run() {
                      AnimateandSlideShow();
                  }
              };
      
              int delay = 0;
              int period = 15000;
              timerAnimate = new Timer();
              timerTask = new TimerTask() {
                  public void run() {
                      mHandler.post(mUpdateResults);
                  }
              };
              timerAnimate.scheduleAtFixedRate(timerTask, delay, period);
      
               Public void AnimateandSlideShow()
                     {
                      imageSwitcher.setImageResource(imageList[curIndex]);
                     ///Here You need To handle curIndex position.
                      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-06-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多