2013-10-01 17 views
-1

我需要沿着圓形路徑移動圓,因爲我使用的是對象動畫器和路徑評估器。所有信息都是動態的,意味着它在接收響應時發生變化,因此可以在運行時更改圓的總數。以下是方法1份,其中各界根據其在屏幕上的立場是,如果用戶釋放觸摸,然後調用此方法定位自己 - :我如何從Object Animator OfObject(..)方法動畫傳遞視圖引用?

public void slideDownSetToCenter() { 

    for (int i = 0; i < leftCurrentRunningAnimation.length; i++) { 

     Logger.i(TAG, "in slide down animation"); 
     if (leftReadyToMove[i]) { 

      if (leftUpQueue.contains(i)) { 
       leftUpQueue.remove(i); 
      } 
      leftAngle = leftSlice * ++leftAllCirclesAngles[i]; 
      Logger.i("circle leftAngle points of curve down", String.valueOf(leftAllCirclesAngles[i])); 
      if (leftAngle > leftAngleTop) { 
       if (i < leftCurrentRunningAnimation.length - 1) { 
        leftReadyToMove[i + 1] = true; // set next circle to 
                // move 
       } 
      } 
      Arrays.fill(leftCurrentRunningAnimation, false); 
      leftCurrentRunningAnimation[i] = true; 

      Logger.i(TAG, "leftAngle" + leftAngle); 

      if (leftReadyToMove[i] == true && leftAngle == leftAngleDownOut) { 

       leftReadyToMove[i] = false; 
       leftDownStack.add(i); 
      } 

      xPosition = (int) (leftCircleCenterX + leftCircleX * Math.cos(leftAngle)); 
      yPosition = (int) (leftCircleCenterY + leftCircleY * Math.sin(leftAngle)); 

      Path = new AnimatorPath(); 
      Path.moveTo(xPosition, yPosition); 
      Path.lineTo(xPosition, yPosition); 
      while (true) { 
       if (leftAngle == leftAngleDownOut) { 
        break; 
       } 

       leftAngle = leftSlice * ++leftAllCirclesAngles[i]; 
       xPosition = (int) (leftCircleCenterX + leftCircleX * Math.cos(leftAngle)); 
       yPosition = (int) (leftCircleCenterY + leftCircleY * Math.sin(leftAngle)); 
       Path.lineTo(xPosition, yPosition); 
       Logger.i(TAG, "path........."); 
      } 
      slideCircleAnimator = ObjectAnimator.ofObject(DynamicCircleSwipeAnimation.this, "leftButtonLocationDynamic", new PathEvaluator(), Path.getPoints().toArray()); 
      slideCircleAnimator.setInterpolator(linearInterpolator); 
      slideCircleAnimator.setDuration(500); 
      context.runOnUiThread(new Runnable() { 

       @Override 
       public void run() { 
        slideCircleAnimator.start(); 
       } 
      }); 

     } 
     break; 
    } 
} 

這裏是對象動畫的動畫製作方法 - :

public void setLeftButtonLocationDynamic(final PathPoint newLoc) { 

    for (int i = 0; i < leftCurrentRunningAnimation.length; i++) { 
     if (leftCurrentRunningAnimation[i] == true) { 
      Logger.i("current button id", String.valueOf(i)); 
      leftArrayOfButtons[i].setTranslationX(newLoc.mX); 
      leftArrayOfButtons[i].setTranslationY(newLoc.mY); 
      break; 
     } 
    } 
} 

在這裏我的動畫不是以正確的方式發生'w hy我需要從Object.OfObject()方法傳遞我的視圖引用,以便我可以在setLeftButtonLocationDynamic(最終PathPoint newLoc,View v)中獲取它。任何人都有任何想法我怎麼能做到這一點?我搜索了很多,試圖開發ObjectAnimator,ValueAnimator和ProperyViewHolder類的自定義類,但是當我從谷歌開放源碼複製它,然後我得到的錯誤。任何幫助是可觀的?

+0

只是創建一個自定義Animarion,將採取更多或代碼 – pskink

+0

少十行@pskink你可以分享任何類似的例子嗎? –

+0

只是擴展動畫類和覆蓋applyTransformation方法 – pskink

回答

-1

在這裏爲了實現這一點,我改變了移動所有圓圈的方法。以前,我使用ObjectAnimator來逐個移動圓圈,現在我正在使用Animator設置x位置和y位置。我同時播放這兩個動畫。

這裏是例子 - :

public void SlideDownFromRightAnimation() { 

    int rightArrayOfButtonsLength = rightArrayOfButtons.length; 

    Logger.i(TAG, "queue " + rightUpQueue.size() + "= stack " + rightDownStack.size()); 
    if (rightUpQueue.size() == rtNumberOfButtons) { 
     Arrays.fill(rightReadyToMove, false); 
     rightReadyToMove[0] = true; 
     rightUpQueue.poll(); 
    } else if (rightDownStack.size() == rtNumberOfButtons) { 
     rightUpQueue.clear(); 
     for (int i = 0; i < rightArrayOfButtonsLength; i++) { 
      rightUpQueue.add(rightDownStack.pop()); 
      rightAllCirclesAngles[i] = rightCircleUpOutPosition; 
     } 
     Arrays.fill(rightReadyToMove, false); 
     rightReadyToMove[0] = true; 
    } 

    for (int i = 0; i < rightArrayOfButtonsLength; i++) { 

     Logger.i(TAG, "in slide down animation"); 
     if (rightReadyToMove[i]) { 

      if (rightUpQueue.contains(rightArrayOfButtons[i].getTag())) { 
       rightUpQueue.remove(i); 
      } 
      rightAngle = rightSlice * --rightAllCirclesAngles[i]; 
      Logger.i("circle rightAngle points of curve down", String.valueOf(rightAllCirclesAngles[i])); 
      if (rightAngle <= rightAngleTop) { 
       if (i < rightArrayOfButtonsLength - 1) { 
        rightReadyToMove[i + 1] = true; // set next circle to 
                // move 
       } 
      } 

      Logger.i(TAG, "rightAngle" + rightAngle); 

      if (rightAngle <= rightAngleDownOut) { 

       rightReadyToMove[i] = false; 
       rightDownStack.add((Integer)rightArrayOfButtons[i].getTag()); 
       rightAllCirclesAngles[i] = rightCircleDownOutPosition; 
       rightStartAnimation(rightAngle, null, i); 
      } else { 
       double rightAngleNext = rightSlice * rightAllCirclesAngles[i]; 

       if (rightAngleNext <= rightAngleDownOut) { 

        rightReadyToMove[i] = false; 
        rightDownStack.add((Integer)rightArrayOfButtons[i].getTag()); 
       } 

       rightStartAnimation(rightAngle, rightAngleNext, i); 
      } 

     } 

    } 

} 

,這裏是右側車輪動畫功能 - :

public void rightStartAnimation(Double rightAngle, Double rightAngleNext, int bttnId) { 
    xPosition = (int) (rightCircleCenterX + rightCircleX * Math.cos(rightAngle)); 
    yPosition = (int) (rightCircleCenterY + rightCircleY * Math.sin(rightAngle)); 

    if (rightAngleNext != null) { 
     xPosition = (int) (rightCircleCenterX + rightCircleX * Math.cos(rightAngleNext)); 
     yPosition = (int) (rightCircleCenterY + rightCircleY * Math.sin(rightAngleNext)); 
    } 

    final ObjectAnimator animation1 = ObjectAnimator.ofFloat(rightArrayOfButtons[bttnId], "x", rightArrayOfButtons[bttnId].getX(), xPosition); 
    animation1.setDuration(0); 
    animation1.setInterpolator(linearInterpolator); 
    final ObjectAnimator animation2 = ObjectAnimator.ofFloat(rightArrayOfButtons[bttnId], "y", rightArrayOfButtons[bttnId].getY(), yPosition); 
    animation2.setDuration(0); 
    animation2.setInterpolator(linearInterpolator); 
    final AnimatorSet set = new AnimatorSet(); 
    set.setInterpolator(linearInterpolator); 
    context.runOnUiThread(new Runnable() { 

     @Override 
     public void run() { 
      set.playTogether(animation1, animation2); 
      set.start(); 
     } 
    }); 
} 
相關問題