【发布时间】:2018-05-17 17:32:06
【问题描述】:
我正在尝试制作围绕圆形旋转的图像视图的动画。 这是当前的代码,但没有使用不同的值重复动画:
public void runAnimation(){
ImageView worldView=findViewById(R.id.imageView);
int radius=worldView.getHeight()*30/70;
int centerx = worldView.getLeft()+radius;
int centery = worldView.getTop()+radius;
//List<Animator> myList = new ArrayList<>();
for (int i=0;i<360;i++) {
/*---I calculate the points of the circle---*/
int angle= (int) ((i * 2 * Math.PI) / 360);
int x= (int) (centerx+(radius*Math.cos(angle)));
int y= (int) (centery+(radius*Math.sin(angle)));
/*---Here carView is the ImageView that need to turn around the worldView---*/
ObjectAnimator animatorX =ObjectAnimator.ofFloat(carView, "x",x);
ObjectAnimator animatorY =ObjectAnimator.ofFloat(carView, "y",y);
ObjectAnimator animatorR =ObjectAnimator.ofFloat(carView, "rotation", i);
animatorX.setDuration(500);
animatorY.setDuration(500);
animatorR.setDuration(500);
AnimatorSet animatorSet=new AnimatorSet();
animatorSet.playTogether(animatorX,animatorY,animatorR);
animatorSet.start();
//myList.add(animatorSet);
}
//AnimatorSet animatorSet=new AnimatorSet();
//animatorSet.playSequentially(myList);
}
注释 ("//") 用于说明我想要创建的内容。 提前感谢您的帮助。
【问题讨论】:
-
由于动画具有 500 毫秒的固定持续时间,并且您正在一起播放它们,您可以简单地从具有特定延迟的循环中启动 AnimatorSet,以使它们连续运行。在调用 start() 之前添加:animator.setStartDelay(i * 500);
标签: android objectanimator animatorset