我需要沿着圓形路徑移動圓,因爲我使用的是對象動畫器和路徑評估器。所有信息都是動態的,意味着它在接收響應時發生變化,因此可以在運行時更改圓的總數。以下是方法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類的自定義類,但是當我從谷歌開放源碼複製它,然後我得到的錯誤。任何幫助是可觀的?
只是創建一個自定義Animarion,將採取更多或代碼 – pskink
少十行@pskink你可以分享任何類似的例子嗎? –
只是擴展動畫類和覆蓋applyTransformation方法 – pskink