Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7727683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:31:15+00:00 2026-06-01T05:31:15+00:00

Requirement: I need to run multiple animations one by one. I’m using onAnimationEnd() to

  • 0

Requirement:

I need to run multiple animations one by one. I’m using onAnimationEnd() to do so.

While animating, in case of a touch event, I need to stop the animations and display a new image in that location.

Problems:

  1. I’m using clearAnimation() in case of onTouch. Because of this, the complete animation got removed. My intention is to stop the animation and and display a new image in the touched portion. How can I achieve this?

  2. Because of clearAnimation(), onAnimationEnd() is getting called multiple times and I’m facing problems in running animations one after another.

  3. Is there any function just to stop the animation instead of clearing it completely? I am using Android 2.1.

@Override
public boolean onTouch(View v, MotionEvent event) {      
    switch(event.getAction()) {
        case MotionEvent.ACTION_UP:
            imageArray[g_animCount - 1].clearAnimation();          
            break;

        default:
            break;
    }

    return true; // indicate event was handled
}

@Override
public void onAnimationEnd(Animation animation) {
    layout.removeView(imageArray[g_animCount - 1]);
    if ( (g_animCount < count))
    {               
        startNextAnimation();
    }
    else
    {
        g_animCount = 0;
        isBegin = false;
    }
}

public void startNextAnimation()
{
     int j = random.nextInt(200);
     layoutParams.setMargins(j, -20, 30, 0);
     layout.addView(imageArray[g_animCount], layoutParams); 
     imageArray[g_animCount].startAnimation(movArray[g_animCount]);
     g_animCount++;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T05:31:16+00:00Added an answer on June 1, 2026 at 5:31 am

    An animation only moves the pixels on the screen, not the position of the object. To set your to stay where it upon end, set your

    animation.setFillAfter(true);
    

    To actually move the position of the object, look into using a modified version of the below code snippet.

    MarginLayoutParams marginParams = new MarginLayoutParams(object.getLayoutParams());
    marginParams.setMargins(left, (top+hol2), left, 0);
    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(marginParams);
    object.setLayoutParams(layoutParams);
    

    Regarding the onAnimationEnd being called multiple times, I would need to see some code.

    The only two ways I know of to manually stop an animation would be

    animation.cancel(); (may not work for 2.1, can't remember)
    

    or

    object.clearAnimation();
    

    Sample Code Below:

        upmotionleft = new TranslateAnimation(0, 0, 0, 600);
        upmotionleft.setDuration(2000);
        upmotionleft.setFillEnabled(true);
        upmotionleft.setAnimationListener(new Animation.AnimationListener() 
        {
            @Override
            public void onAnimationStart(Animation animation) 
            {}
            @Override
            public void onAnimationEnd(Animation animation) 
            {
                //sets to wherever I want the final object to be
                MarginLayoutParams marginParams = new MarginLayoutParams(object.getLayoutParams());
                marginParams.setMargins(left, top-hol2, left, 0);
                RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(marginParams);
                object.setLayoutParams(layoutParams);
    
                //starts next animation
                object.startAnimation(nextAnimation);
            }
    
            @Override
            public void onAnimationRepeat(Animation animation) 
            {}
        });
    
    object.startAnimation(upmotionleft);
    

    This code is copied and pasted from a project of mine but it has been changed somewhat, should still run.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have requirement like this: On one server(linux) I need to run 2 instances
I have one requirement in my android application in which I need to run
I have a requirement that I need to run the tests through commandline as
I have a requirement where i need to open command prompt and run a
I have a requirement where I need to run an RFC from an ETL
I have a requirement in which the SSRS 2008 reports need to be run
Wondering if I could get some advice and direction on this following requirement: Need
Hi i have a requirement i need your help for it:- I have a
I am having a very simple requirement.I need the border on left and right
I had a requirement where I need to clear off the select all checkbox

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.