5
votes

To all,

I have animated image with Frame animations that I'm moving from up behind a view and onto the screen. When the TranslateAnimation is done I want to keep the finish position so setFillAfter is set to true.

My issue is that the Frame Animation is stopped when the TranslateAnimation is finished. How can I restart or keep the Frame Animation going?

    <?xml version="1.0" encoding="utf-8"?>
    <animation-list xmlns:android="http://schemas.android.com/apk/res/android"
     id="selected" android:oneshot="false">
         <item android:drawable="@drawable/a" android:duration="200" />
         <item android:drawable="@drawable/b" android:duration="200" />
         <item android:drawable="@drawable/c" android:duration="200" />
     </animation-list>

    loadingView = (RelativeLayout) findViewById(R.id.loadingBar);
    loadingView.setVisibility(View.VISIBLE);
    loadingImage = (ImageView) loadingView.findViewById(R.id.loading);
    loadingImage.setBackgroundResource(R.drawable.loading);
    animateImages = (AnimationDrawable) loadingImage.getBackground();

    translateAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
                                                Animation.RELATIVE_TO_SELF,0.0f, Animation.RELATIVE_TO_SELF, -1.0f);
    translateAnimation.setInterpolator(new AccelerateInterpolator());
    translateAnimation.setDuration(2000); 
    translateAnimation.setFillEnabled(true);
    translateAnimation.setFillAfter(true);      

    translateAnimation.setAnimationListener(new AnimationListener() 
    {
        @Override
        public void onAnimationStart(Animation animation) 
        {
            // TODO Auto-generated method stub
                     animateImages.start();                             
        }

        @Override
        public void onAnimationEnd(Animation arg0) 
        {

        }

        @Override
        public void onAnimationRepeat(Animation animation) 
        {
            // TODO Auto-generated method stub

        }
    });

    loadingView.startAnimation(translateAnimation); 
1
Can you show your frame animation xml?Lalit Poptani
Updated the question with the frame animation xml.Koppo
The only other thing I noticed when I touch the screen I see the animation start for as long as I'm touch the screen. It stops when I take my hand off it.Koppo

1 Answers

0
votes

I had the same issue, and couldn't find a definitive solution. So a workaround for me was adding a long animation at the end, almost without changes (a Translation animation moving just a few pixels after a long while), so the frame by frame animation keeps playing during some minutes. For my app that's enought. Maybe you find this idea useful.