-1

我需要沿圆形路径移动圆圈,因为我正在使用 Object Animator 和 Path evaluator。所有信息都是动态的,意味着当我收到响应时它正在发生变化,因此可以在运行时更改圆圈的总数。这是第 1 部分所有圆圈都根据它们在屏幕上的位置定位自己的方法,如果用户释放触摸,则调用此方法-:

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;
        }
    }
}

在这里,我的动画没有以正确的方式发生,这就是为什么我需要从 Object.OfObject() 方法传递我的视图引用,以便我可以在 setLeftButtonLocationDynamic(final PathPoint newLoc,View v) 中获取它。有没有人知道怎么做我这样做吗?我搜索了很多并尝试开发 ObjectAnimator、ValueAnimator 和 ProperyViewHolder 类的自定义类,但是当我从谷歌开源复制它时,我得到了错误。有任何帮助吗?

4

1 回答 1

-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();
        }
    });
}
于 2013-10-23T07:07:50.230 回答