Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

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

And the xml code is:

<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. 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.

like image 839
Wesley Avatar asked Jul 02 '12 15:07

Wesley


1 Answers

Have you tried animation configuration like this

animtopOut.setRepeatCount(Animation.INFINITE);

animtopOut.setRepeatMode(Animation.RESTART);

animtopOut.setInterpolator(new LinearInterpolator());

?

like image 78
smora Avatar answered Nov 11 '22 13:11

smora