我有一个 ImageView 图像。我需要将此图像向右旋转 90 度,然后将其从左向右移动。我设法做到了。我使用了 AnimationListener并在旋转完成后开始moveAnimation()。但是在运动图像恢复到原来的样子之前(旋转之前)。
用于旋转rotation.xml的xml代码
<?xml version="1.0" encoding="utf-8"?>
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:interpolator="@android:anim/linear_interpolator"
android:toDegrees="90"
android:pivotX="50%"
android:pivotY="50%"
android:duration="1000"
android:startOffset="0"
/>
旋转动画()
private void rotateAnimation(){
Animation rotation = AnimationUtils.loadAnimation(getContext(), R.anim.rotate);
rotation.setRepeatCount(0);
rotation.setFillAfter(true);
rotation.setAnimationListener(new AnimationListener() {
public void onAnimationEnd(Animation animation) {
moveAnnimation();
}
});
移动动画()
private void moveAnnimation(){
TranslateAnimation moveLefttoRight = new TranslateAnimation(0, 2000, 0, 0);
moveLefttoRight.setDuration(1000);
moveLefttoRight.setFillAfter(true);
moveLefttoRight.setAnimationListener(new AnimationListener() {
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
}
});
image.startAnimation(moveLefttoRight);
}