Android:旋转动画和移动动画的组合

Android:旋转动画和移动动画的组合,android,animation,image-rotation,Android,Animation,Image Rotation,我有一个图像视图图像。我需要将这张图片向右旋转90度,然后从左向右移动。我设法做到了。我使用了AnnimationListener,旋转完成后,我开始moveAnimation()。但在运动图像恢复到原始外观之前(旋转之前) rotation.xml的xml代码 移动地址() 对于旋转和平移动画对象,都需要setFillAfter(true) 如果fillAfter为true,则此动画执行的转换将在完成时持续。如果未设置,则默认为false。请注意,这适用于单个动画以及使用AnimationS

我有一个图像视图图像。我需要将这张图片向右旋转90度,然后从左向右移动。我设法做到了。我使用了AnnimationListener,旋转完成后,我开始moveAnimation()。但在运动图像恢复到原始外观之前(旋转之前)

rotation.xml的xml代码

移动地址()


对于旋转和平移
动画
对象,都需要
setFillAfter(true)

如果fillAfter为true,则此动画执行的转换将在完成时持续。如果未设置,则默认为false。请注意,这适用于单个动画以及使用AnimationSet链接动画时。

下面是我的代码,您需要AnimationSet来实现链接动画效果

public class MainActivity extends Activity {

    ImageView image = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        image = (ImageView)findViewById(R.id.imageview);

        animateImageView();
    }

    private void animateImageView() {
        AnimationSet set = new AnimationSet(true);
        set.setFillAfter(true);

        Animation rotation = AnimationUtils.loadAnimation(this, R.anim.rotation);
        TranslateAnimation moveLefttoRight = new TranslateAnimation(0, 200, 0, 0);
        moveLefttoRight.setDuration(1000);
        moveLefttoRight.setStartOffset(1000);

        set.addAnimation(rotation);
        set.addAnimation(moveLefttoRight);

        image.startAnimation( set );
    }   
} 

我当然做到了!这就是问题所在!我的缺点不是我没有说。我稍后会添加一些代码,但简而言之,我使用xml动画文件进行旋转和简单移动动画,没有xml文件。应该可以,我已经测试了代码。正如我从您的要求中了解到的,它应该旋转90度(无复位),然后向右平移(无复位)。也许我错了。你能给出你用来旋转和移动图像的示例代码吗?好的,但我给你我的意见。。尝试使用矩阵进行旋转,使用类似矩阵进行平移,这样矩阵将集中,图像视图将不会重置。在执行任何矩阵操作之前,不要忘记将imageview的属性scaletype设置为matrix。
    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);
}
public class MainActivity extends Activity {

    ImageView image = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        image = (ImageView)findViewById(R.id.imageview);

        animateImageView();
    }

    private void animateImageView() {
        AnimationSet set = new AnimationSet(true);
        set.setFillAfter(true);

        Animation rotation = AnimationUtils.loadAnimation(this, R.anim.rotation);
        TranslateAnimation moveLefttoRight = new TranslateAnimation(0, 200, 0, 0);
        moveLefttoRight.setDuration(1000);
        moveLefttoRight.setStartOffset(1000);

        set.addAnimation(rotation);
        set.addAnimation(moveLefttoRight);

        image.startAnimation( set );
    }   
}