1

我有这段代码,我想同时旋转和缩放ImageView

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

rotate()然后我尝试应用该方法startScale(),但这对两者都不起作用。

有没有人有办法解决吗?

4

4 回答 4

3

您可以使用名为NineOldAndroids的库。那里有 AnimatorSet 的 playTogether 功能。

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

您还可以添加监听器

animation.addListener(new AnimationListener(){
   onAnimationStart....
   onAnimationRepeat...
   onAnimationEnd...
   onAnimationCancel...
});
于 2015-08-27T15:43:31.897 回答
1

你可以使用这个库:https ://github.com/Yalantis/uCrop

只需选择图像或编码图像路径(如果您不希望用户更改图像)。

于 2016-04-12T06:59:54.183 回答
0

从 Honeycomb 开始动画更容易实现,来源:ViewPropertyAnimator

例如改变视图坐标:

ObjectAnimator animX = ObjectAnimator.ofFloat(myView, "x", 50f);
ObjectAnimator animY = ObjectAnimator.ofFloat(myView, "y", 100f);
AnimatorSet animSetXY = new AnimatorSet();
animSetXY.playTogether(animX, animY);
animSetXY.start();
于 2015-08-27T15:30:23.920 回答
0

我想你应该使用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();
于 2015-08-27T15:27:23.033 回答