Search code examples
androidanimationrotateanimation

Emotion roll from center to right using Android animation


I want my ImageView roll from center of screen to right. I use this code at the moment, but it doesn't roll the image.

final AnimationSet rollingIn = new AnimationSet(true);

Animation moving = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, -1f, Animation.RELATIVE_TO_PARENT, 0, Animation.RELATIVE_TO_PARENT, 0,
    Animation.RELATIVE_TO_PARENT, 0);
moving.setDuration(5000);

rollingIn.addAnimation(moving);

Solution

  • try

    final AnimationSet rollingIn = new AnimationSet(true);
        Animation moving = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 5, Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0);
        moving.setDuration(1000);
        final Animation rotating = new RotateAnimation(0, 720, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        rotating.setDuration(1000);
    
        rollingIn.addAnimation(rotating);
        rollingIn.addAnimation(moving);