gpt4 book ai didi

java - 同时旋转和缩放图像

转载 作者:行者123 更新时间:2023-11-29 03:05:48 26 4
gpt4 key购买 nike

我有这段代码,我想同时旋转和缩放 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() 方法,但这对两者都不起作用。

有没有人有解决办法?

最佳答案

您可以使用名为 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...
});

关于java - 同时旋转和缩放图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32253158/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com