- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试制作围绕圆形旋转的 ImageView 的动画。这是当前有效但不重复具有不同值的动画的代码:
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);
}
评论(“//”)在这里是为了说明我想要创建的内容。预先感谢您的帮助。
最佳答案
您可以使用 addListener(Animator.AnimatorListener listener)
向每个 AnimatorSet
添加一个监听器。
for (int i=0;i<360;i++) {
// ...skipped some lines here...
AnimatorSet animatorSet=new AnimatorSet();
animatorSet.playTogether(animatorX,animatorY,animatorR);
myList.add(animatorSet);
animatorSet.addListener(myListener);
}
其中 myListener 定义如下:
private Animator.AnimatorListener myListener = new Animator.AnimatorListener(){
@Override
public void onAnimationStart(Animator animation){
// no op
}
@Override
public void onAnimationRepeat(Animator animation){
// no op
}
@Override
public void onAnimationCancel(Animator animation){
// no op
}
@Override
public void onAnimationEnd(Animator animation){
startNextAnimation();
}
};
除此之外,您还需要一些变量 private int counter;
来遍历列表。在开始第一个动画之前,将其设置为零:
counter = 0;
myList.get(0).start();
开始下一个动画(如果还有的话):
private void startNextAnimation(){
counter++;
if(counter == myList.size()){
return;
}
myList.get(counter).start();
}
关于android - 如何顺序播放AnimatorSet的列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50397370/
我正在尝试使用 AnimatorSets 链接一组动画。 我有这样的东西: AnimatorSet sequentialSet = new AnimatorSet(); sequentialSet.p
我正在尝试让一个动画在另一个动画结束后开始。我正在使用动画属性并将对象定义为“AnimatorSet”。问题是第一个动画开始时没有问题,但第二个动画从未开始。 public void moveGrou
我需要的是一个可无限重复的 AnimatorSet(由 2 个连续的 animations 组成),同时也是一种在安全的情况下停止这些 animations 的方法方式(即最终状态与起始状态相同)。例
我正在尝试设置一个动画师监听器,所以最终对象动画师会发生一些事情!到目前为止,这是我的代码: as=new AnimatorSet(); as.addListener(new Ani
我需要将以下动画应用于 imageView: 1. alpha (0 -> 1) and scale (0 -> 1) in 500ms 2. pause for 1000ms 3. alpha (1
我想将 View “闪烁”3 倍(缩小和放大,重复 3 倍)。它有效,但不适用于 AnimatorSet。 这个有效: ibOffers.animate().scaleX(0.7f).scaleY(0
我们想在下面的方法中设置结束监听器: private void animation1() { ObjectAnimator scaleXAnimation = ObjectAnima
我无法弄清楚这段代码有什么问题。我通过调用 AnimatorSet.playTogether() 方法一起播放两个 Animator。但是 onAnimationEnd() 回调只被调用一次。为什么会
我已经尝试了几个小时,我觉得是时候放弃了。如何循环在 xml 中定义的 AnimatorSet? 我在单个 objectAnimator 上尝试了 star
我正在使用 Sceneform 创建一个播放动画的 android 应用程序。我正在尝试使用 AnimatorSet 按顺序启动多个 Animator。该代码在尝试播放两个动画时完美运行,但每当我添加
我正在使用 AnimatorSet 创建动画,当它结束时我想将 View 留在原处。 代码是这样的: mLastAnimation = new AnimatorSet(); mLastAnimatio
您好,我正在使用 AnimatorSet 和 ValueAnimator 将多个动画应用到一个 View 。 当用户触摸 View 时,连续的动画会应用到 View 。当用户在 View 上移动手指时
我创建了一个 AnimatorSet s1。 我想使用 s1 AnimatorSet 而不是 R.anim.slide_in_top 。 如何让事务使用s1? private void showsys
我有以下代码,它将图像分成两半并在不同方向为每个部分设置动画: final AnimatorSet mSetAnim = new AnimatorSet(); final Animator topAn
第一次尝试 RoboGuice。到目前为止,注入(inject) View 的一切都运行顺利。 自从我在 tutorial 中看到我可以注入(inject)资源我试图添加一个 AnimatorSet
我正在使用这样的 AnimatorSet playSequentially 方法: AnimatorSet set = new AnimatorSet(); ObjectAnimator in = O
我已经在某些设备上使用 ObjectAnimator 类进行了一些测试,除了一台设备外一切正常:Huawei P8 Lite 2017。 在此设备上,View 在动画开始时“消失”并在结束时“出现”。
这是我需要通过AnimatedVectorDrawableCompat实现的效果。 vector_drawable_anim.xml vector_drawable.xml
我有以下 AnimatorSet 方法: private AnimatorSet dialCenterThrob() { int bpm = workoutStream.getHeartRat
我有一个关于 Android 中的 ObjectAnimator 的问题。我正在尝试模拟一个弹跳效果,其中 View 向上滑动(减小 Y 值)并在相同数量“n”之后返回,然后 View 再次向上和向下
我是一名优秀的程序员,十分优秀!