Android: 如何制作从最后一个位置开始的动画?

Android: How to make animation starting from the last position?

我有一个 ImageButton,它应该根据加速器角度改变它的位置。不幸的是,我不知道如何从最后一个位置开始动画......请帮助我理解。我想,问题出在 RELATIVE_TO_SELF,这是绝对的事情。现在动画从同一个地方开始。提前谢谢你:)

    public void animateButton (float newAngle) {
    if (animation != null) {
    if (!animation.hasEnded()) {
        return;
    }}

    float goalX = 0f;
    float goalY = 0f;
    if (newAngle == 0) {
        return;
    }
    if (newAngle < 0 ) {
        newAngle = Math.abs(newAngle) + 270;
    }


    if ((newAngle > 0) || (newAngle <= 15)) {
        goalX = 0f;
        goalY = - 1f;
    } else if ((newAngle > 15) || (newAngle <= 30)) {
        goalX = - 0.5f;
        goalY = - 0.5f;
    } else if ((newAngle > 30) || (newAngle <= 90)) {
        goalX = - 1f;
        goalY = 0f;
    } else if ((newAngle > 90) || (newAngle <= 180)) {
        goalX = - 0.5f;
        goalY = 0.5f;
    } else if ((newAngle > 180) || (newAngle <= 195)) {
        goalX = 0f;
        goalY = 1f;
    } else if ((newAngle > 195) || (newAngle <= 240)) {
        goalX = 0.5f;
        goalY = 0.5f;
    } else if ((newAngle > 240) || (newAngle <= 300)) {
        goalX = 1f;
        goalY = 0f;
    } else if ((newAngle > 300) || (newAngle < 360)) {
        goalX = 0.5f;
        goalY = - 0.5f;
    } 


animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 1f, Animation.RELATIVE_TO_SELF, goalX, Animation.RELATIVE_TO_SELF, 1.0f, Animation.RELATIVE_TO_SELF, goalY);          
animation.setDuration(1000);
animation.setRepeatCount(1);
animation.setRepeatMode(1);
animation.setFillAfter(true);
ib.startAnimation(animation);       


}

如果 setFillAfter(boolean filled) 不起作用,您可以使用 Property 动画。他们更改布局参数,因此您可以在她从最后一个位置结束后开始动画。

另请参阅this video