0

ImageView画像があります。この画像を右に90度回転させ、その後、この画像を左から右に移動する必要があります。私はそれを行う方法を管理しました。AnnimationListenerを使用し、回転が終了した後、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"
/>

rotateAnimation()

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

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

1 に答える 1

0

setFillAfter(true)回転オブジェクトと平行移動オブジェクトの両方に必要ですAnimation

Animation.html#setFillAfter(ブール値)

If fillAfter is true, the transformation that this animation performed will persist when it is finished. Defaults to false if not set. Note that this applies to individual animations and when using an AnimationSet to chain animations.

以下は私のコードです。連鎖アニメーション効果を実現するには、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 );
    }   
} 
于 2012-08-10T09:20:09.187 に答える