简体   繁体   English

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

[英]Translate animation works perfectly when defining with XML and only once perfectly by code - Android

I'm getting this weird issue. 我遇到了这个奇怪的问题。 Basically I'm animating a view with translate animation. 基本上我用翻译动画制作一个视图。 (Translate into the screen and out via 2 different events) My code for translate animation is: (转换到屏幕并通过2个不同的事件输出)我的翻译动画代码是:

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

And the xml code is: 而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>

Setting it using the code: 使用代码进行设置:

final Animation animtopOut = AnimationUtils.loadAnimation(mContext, R.anim.header_animate_out);

When I trigger the animation it works fine if I use the xml animation properties. 当我触发动画时,如果我使用xml动画属性,它可以正常工作。 The problem is when i use it via code. 问题是我通过代码使用它。 Which is what I want. 这就是我想要的。 It runs with translate animation only for the first time. 它仅在第一次使用翻译动画时运行。 The second time, when it is triggered, the view is inside the screen without animation. 第二次,当它被触发时,视图在屏幕内没有动画。 Please some one help me if I'm missing any properties. 如果我遗漏任何财产,请有人帮助我。 Thanks. 谢谢。


EDIT : (extra info) 编辑:(额外信息)

There are actually two different animations that are triggered on the same view via two different events. 实际上有两种不同的动画通过两个不同的事件在同一视图上触发。 I have actually posted one animation property. 我实际上发布了一个动画属性。 The other is almost the same. 另一个几乎是一样的。 with just values are different. 只是价值观是不同的。

Have you tried animation configuration like this 你试过像这样的动画配置吗?

animtopOut.setRepeatCount(Animation.INFINITE);

animtopOut.setRepeatMode(Animation.RESTART);

animtopOut.setInterpolator(new LinearInterpolator());

?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM