1

I have this code and I want to rotate and scale an ImageView at the same time:

public class LayoutPunteggio extends RelativeLayout {

TextView ok;
LayoutInflater inflater;
RotateAnimation rotateAnimation1;

public LayoutPunteggio(Context context) {
    super(context);
    inflater = LayoutInflater.from(context);
    init();
}


public void init() {
    mano = new ImageView(getContext());
    mano.setImageResource(R.drawable.mano);
    mano.setX(100);
    mano.setY(100);
    addView(mano);

    startScale(mano);
    rotate();
}

public void rotate() {
    rotateAnimation1.setInterpolator(new LinearInterpolator());
    rotateAnimation1.setDuration(1000);
    rotateAnimation1.setRepeatCount(-1);
    mano.startAnimation(rotateAnimation1);
}

public void startScale(View view){
    ScaleAnimation animation;
    animation=new ScaleAnimation(1,2,1,2,1000, 1000);
    animation.setDuration(1000);
    view.startAnimation(animation);
}
}

I tried to apply the method rotate() then startScale(), but this doesn't work for both.

Does anyone have a solution?

adelphus
  • 10,116
  • 5
  • 36
  • 46
LolloAAA
  • 112
  • 10
  • Use an `AnimationSet` http://developer.android.com/reference/android/view/animation/AnimationSet.html – ci_ Aug 27 '15 at 15:19

4 Answers4

3

You can use a library called NineOldAndroids. There you have playTogether function of the AnimatorSet.

AnimatorSet animation = new AnimatorSet();
animation.playTogether(
   ObjectAnimator.ofFloat(yourImageView, "rotation", 0, 360),
   ObjectAnimator.ofFloat(yourImageView, "scaleX", 1, 2f),
   ObjectAnimator.ofFloat(yourImageView, "scaleY", 1, 2f)
);
animation.setDuratio(1000);
animation.start();

You can also add a listener

animation.addListener(new AnimationListener(){
   onAnimationStart....
   onAnimationRepeat...
   onAnimationEnd...
   onAnimationCancel...
});
Alex
  • 54
  • 3
1

You can use this library: https://github.com/Yalantis/uCrop

Just pick the image or code the image path(if you don't want the user to change the image).

Adhish Lal
  • 149
  • 1
  • 3
  • 8
0

I guess you should use AnimationSet:

AnimationSet as = new AnimationSet(true);

// config rotation animation
RotateAnimation ra = new RotateAnimation(...);
ra.setDuration(1000);
...

// config scale animation
ScaleAnimation sa = new ScaleAnimation(...);
sa.setDuration(1000);
...

// Add animations
as.addAnimation(ra);
as.addAnimation(sa);

as.start();
Alex S. Diaz
  • 2,637
  • 2
  • 23
  • 35
0

Starting from Honeycomb animations are lot easier to implement, source: ViewPropertyAnimator

For instance changing coordinates of view:

ObjectAnimator animX = ObjectAnimator.ofFloat(myView, "x", 50f);
ObjectAnimator animY = ObjectAnimator.ofFloat(myView, "y", 100f);
AnimatorSet animSetXY = new AnimatorSet();
animSetXY.playTogether(animX, animY);
animSetXY.start();
Konstantin Berkov
  • 1,193
  • 3
  • 14
  • 27