Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/221.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用XML定义时,Translate动画可以完美地工作,而使用代码Android只能完美地工作一次_Android_Android Layout_Android Animation - Fatal编程技术网

使用XML定义时,Translate动画可以完美地工作,而使用代码Android只能完美地工作一次

使用XML定义时,Translate动画可以完美地工作,而使用代码Android只能完美地工作一次,android,android-layout,android-animation,Android,Android Layout,Android Animation,我有个奇怪的问题。基本上,我正在使用“平移”动画设置视图的动画。(通过两个不同的事件转换到屏幕和输出)我的转换动画代码是: final Animation animtopOut = new TranslateAnimation(0, 0, 0, -mainHeaderlayout.getMeasuredHeight()); animtopOut.setDuration(500); animtopOut.se

我有个奇怪的问题。基本上,我正在使用“平移”动画设置视图的动画。(通过两个不同的事件转换到屏幕和输出)我的转换动画代码是:

    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>
触发动画时,如果使用xml动画属性,效果会很好问题是当我通过代码使用它时。这就是我想要的。第一次仅使用平移动画运行。第二次触发时,视图在屏幕内,没有动画。如果我丢失了什么东西,请找个人来帮我。谢谢


编辑:(额外信息)


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

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

animtopOut.setRepeatCount(Animation.INFINITE);

animtopOut.setRepeatMode(Animation.RESTART);

animtopOut.setInterpolator(new LinearInterpolator());

在我的例子中,这一行让我大开眼界:animtopOut.setInterpolator(新的LinearInterpolator());
animtopOut.setRepeatCount(Animation.INFINITE);

animtopOut.setRepeatMode(Animation.RESTART);

animtopOut.setInterpolator(new LinearInterpolator());