2013-01-13 71 views
0

enter image description hereenter image description hereAnimationDrawable創建一個無限循環

我使用AnimationDrawable創建由框架效應的框架,我想,當圖像變化,圓點一起換,我的代碼創建一個無限循環,如果我關閉While(mframeAnimation.isRunning())然後它只檢查一次值並停止。

問:

所以,我應該怎麼做才能創造無限的檢查,收聽或類似的東西來改變圓圖像的變化是什麼時候?

private void selectDot(int arg2) { 
      // TODO Auto-generated method stub 
      for(int i=0;i<imageView.length;i++){ 
       if(i==arg2) imageView[i].setImageResource(R.drawable.black_circle); 
       else imageView[i].setImageResource(R.drawable.gray_circle); 
      } 
     } 

     class Starter implements Runnable { 
      public void run() { 
       mframeAnimation.start(); 
       while(mframeAnimation.isRunning()){ 
        // Get the frame of the animation 
        Drawable currentFrame, checkFrame; 
        currentFrame = mframeAnimation.getCurrent(); 

        int frameNumber; 
        // Checks the position of the frame 
        for (int i = 0; i < mframeAnimation.getNumberOfFrames(); i++) { 
         checkFrame = mframeAnimation.getFrame(i); 
         if (checkFrame == currentFrame) { 
          frameNumber = i; 
    //      Toast.makeText(getActivity(), Integer.toString(frameNumber), Toast.LENGTH_SHORT).show(); 
          selectDot(frameNumber); 
          break; 
         } 
        } 
        } 
      } 
    } 
+0

和你的問題是?通常它有助於指出你的期望和實際發生的事情 –

+0

我認爲這很清楚,但我編輯了,謝謝 – Marckaraujo

+1

@Marckaraujo我做了一個非常類似的廣告輪播也,我開始這樣做,因爲你正在做它,然後發現ViewFlipper使用起來更好,方式也更快,它通過提供的所有圖像構建在動畫製作器中,讓我知道如果您需要更多信息,我可以爲您提供一些代碼。 –

回答

1

This的ViewFlipper我申請TP讓我的旋轉木馬的效果,我調整了動畫位,使其適合正是我想要的。所以是ViewFlipper是你的答案。

+0

你知道我應該用什麼監聽器嗎? – Marckaraujo

+0

這是更好,然後我在做什麼,但我仍然不能做到這一點... – Marckaraujo

+0

@Marckaraujo爲什麼它不工作什麼是你的問題?讓我知道我該怎麼幫忙?我已經實現了我的旋轉木馬,它的作品魅力 –