我遇到了这个奇怪的问题。基本上,我正在使用翻译动画为 View 设置动画。 (通过 2 个不同的事件转换到屏幕和输出)我的转换动画代码是:
final Animation animtopOut = new TranslateAnimation(0, 0, 0, -mainHeaderlayout.getMeasuredHeight());
animtopOut.setDuration(500);
animtopOut.setFillAfter(true);
mainHeaderlayout.setAnimation(animtopOut);
xml代码是:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:interpolator="@android:anim/accelerate_interpolator" >
<translate
android:fromYDelta="0%p"
android:toYDelta="-99%p"
android:duration="600"
android:fillAfter="true">
</translate>
</set>
使用代码设置:
final Animation animtopOut = AnimationUtils.loadAnimation(mContext, R.anim.header_animate_out);
当我触发动画时,如果我使用 xml 动画属性,它会正常工作。 问题是当我通过代码使用它时。这就是我想要的。它仅在第一次运行时带有平移动画。 第二次,当它被触发时, View 在没有动画的屏幕内。如果我缺少任何属性,请有人帮助我。谢谢。
编辑:(额外信息)
实际上有两个不同的动画是通过两个不同的事件在同一个 View 上触发的。我实际上已经发布了一个动画属性。另一个几乎是一样的。只是值(value)观不同。
最佳答案
你试过这样的动画配置吗
animtopOut.setRepeatCount(Animation.INFINITE);
animtopOut.setRepeatMode(Animation.RESTART);
animtopOut.setInterpolator(new LinearInterpolator());
?
关于android - 翻译动画在使用 XML 定义时完美运行,并且仅通过代码完美运行一次 - Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11296950/