我有一个ImageButton应该根据加速器角度改变它的位置。不幸的是,我不知道如何从最后一个位置开始动画...请帮助我理解。我想,问题在于RELATIVE_TO_SELF,ABSOLUTE的东西。现在动画在同一个地方开始。提前谢谢你:)
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);
}
答案 0 :(得分:0)
如果setFillAfter(boolean filled)
不起作用,您可以使用Property动画。它们会更改布局参数,因此您可以在从最后一个位置结束后开始动画。
另请查看this video。