【问题标题】:How to set an offset of ImageView between the animation and its repeat in TranslateAnimation如何在 TranslateAnimation 中设置动画与其重复之间的 ImageView 偏移量
【发布时间】:2013-09-12 21:20:32
【问题描述】:

我有一个 ImageView,它位于屏幕中间。我使用以下代码创建了一个 TranslateAnimation 以将 ot 移动到屏幕的右边缘:

      logoAnimationLeft2Right = new TranslateAnimation(0, screenWidth/2+imageWidth, 0, 0);
      logoAnimationLeft2Right.setDuration(500);
      logoAnimationLeft2Right.setFillAfter(false);
      logoAnimationLeft2Right.setRepeatMode(Animation.REVERSE);
      logoAnimationLeft2Right.setRepeatCount(1);

使用它,我的 ImageView 会转到右边缘,然后从右侧回滚到中心。我想创建一个偏移量,使 ImageView 返回到屏幕的左侧并返回到中心(看起来“围绕”中心)。

我应该怎么做才能在动画和它的反向重复之间产生这种偏移?

【问题讨论】:

  • 你可以使用自定义插值器,试试吧
  • 谢谢你的提示,这次我跳过了,我的动画很简单,但我最终会尝试一下:)
  • 只需像你一样创建一个 TranslateAnimarion 但没有任何重复的东西并设置一个像 Math.sin(input * 2 * Math.PI) 这样的插值器,就是这样,没有重复没有复杂的动画集,简单,简单,简单

标签: android android-animation translate-animation


【解决方案1】:

使用AnimationSet,包含右侧动画和左侧动画,依次循环播放。

【讨论】:

  • 好主意,我创建了一个 AnimationSet 并设置了第二个动画的 startOffset。但是,它们是反向播放的:延迟的动画首先开始,然后是另一个。我怎样才能改变它?
  • 这么奇怪?尝试调试和检查。你也可以使用Animator/AnimatorSet 来实现。你能粘贴你的代码吗?
  • 这里是当前播放动画的代码: logoAnimationLeft2Right = new TranslateAnimation(0, width / 2 + imageWidth, 0, 0); logoAnimationLeft2Right.setDuration(500); logoAnimationLeft2Right2 = new TranslateAnimation(0 - 宽度 / 2 - imageWidth, 0, 0, 0); logoAnimationLeft2Right2.setStartOffset(500); logoAnimationLeft2Right2.setDuration(500); setLeft2Right.addAnimation(logoAnimationLeft2Right); setLeft2Right.addAnimation(logoAnimationLeft2Right2);
  • 我改成 XML 但结果是一样的:它首先从左到中然后从中到右。 schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_decelerate_interpolator">
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-09-19
  • 1970-01-01
  • 2021-03-16
  • 1970-01-01
  • 2012-10-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多