使用XML定义时,翻译动画效果非常好,而且只有代码完美一次 - Android

Wes*_*ley 9 android android-animation android-layout

我遇到了这个奇怪的问题.基本上我用翻译动画制作一个视图.(转换到屏幕并通过2个不同的事件输出)我的翻译动画代码是:

    final Animation  animtopOut = new TranslateAnimation(0, 0, 0, -mainHeaderlayout.getMeasuredHeight());
                    animtopOut.setDuration(500);
                    animtopOut.setFillAfter(true);
mainHeaderlayout.setAnimation(animtopOut);
Run Code Online (Sandbox Code Playgroud)

而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>
Run Code Online (Sandbox Code Playgroud)

使用代码进行设置:

final Animation animtopOut = AnimationUtils.loadAnimation(mContext, R.anim.header_animate_out);
Run Code Online (Sandbox Code Playgroud)

当我触发动画时,如果我使用xml动画属性,它可以正常工作.问题是我通过代码使用它.这就是我想要的.它仅在第一次使用翻译动画时运行.第二次,当它被触发时,视图在屏幕内没有动画.如果我遗漏任何财产,请有人帮助我.谢谢.


编辑:(额外信息)

实际上有两种不同的动画通过两个不同的事件在同一视图上触发.我实际上发布了一个动画属性.另一个几乎是一样的.只是价值观是不同的.

smo*_*ora 4

你尝试过这样的动画配置吗

animtopOut.setRepeatCount(Animation.INFINITE);

animtopOut.setRepeatMode(Animation.RESTART);

animtopOut.setInterpolator(new LinearInterpolator());
Run Code Online (Sandbox Code Playgroud)