Android 如何从Object(..)方法动画的Object Animator传递视图引用?

Android 如何从Object(..)方法动画的Object Animator传递视图引用?,android,Android,我需要沿着圆形路径移动圆,因为我使用的是对象动画和路径计算器。所有信息都是动态的,这意味着当我收到响应时它会发生变化,以便在运行时可以更改圆的总数。这是方法的第一部分,其中所有圆都根据它们在屏幕上的位置来定位自己也就是说,如果用户释放触摸,则调用此方法-: public void slideDownSetToCenter() { for (int i = 0; i < leftCurrentRunningAnimation.length; i++) { Logg

我需要沿着圆形路径移动圆,因为我使用的是对象动画和路径计算器。所有信息都是动态的,这意味着当我收到响应时它会发生变化,以便在运行时可以更改圆的总数。这是方法的第一部分,其中所有圆都根据它们在屏幕上的位置来定位自己也就是说,如果用户释放触摸,则调用此方法-:

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 slideDownSetToCenter(){
对于(int i=0;ileftAngleTop){
if(i
以下是对象动画师的动画方法-:

  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;
        }
    }
}
public void setLeftButtonLocationDynamic(最终路径点newLoc){
对于(int i=0;i

这里我的动画不是以正确的方式发生的,这就是为什么我需要从Object.OfObject()方法传递我的视图引用,以便我可以在setLeftButtonLocationDynamic(最终路径点newLoc,视图v)中获得它。有人知道我该如何做吗?我搜索了很多,并尝试开发ObjectAnimator的自定义类,ValueAnimator和PropertyViewHolder类,但当我从google开源复制它时,我在这方面遇到了错误。有什么帮助吗?

为了实现这一点,我改变了移动所有圆圈的方法。以前,我使用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);
            }

        }

    }

}

只需创建一个自定义动画,大约需要10行code@pskink你能分享一些类似的例子吗?只需扩展动画类并覆盖applyTransformation方法object animator仅用于此类用途。既然object animator为我提供了此类功能,为什么我要扩展并定制它?为什么?因为正如我所说的,您只需十行代码就可以沿着循环路径移动视图,现在将其与您的代码进行比较。。。
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();
        }
    });
}