Java – How to stop the animation when needed and start it instantly in android

How to stop the animation when needed and start it instantly in android… here is a solution to the problem.

How to stop the animation when needed and start it instantly in android

I’m new to android and I need help.

When I click on a button on my keyboard that has the same label as the image, I expect the image that falls from the top of the screen to become invisible. Although I have implemented the above points, the problem arises when I want to show the next animation again immediately after the previous image is not visible. Here is my animation code.

public void startAnimation(final ImageView aniView) 

animator= ValueAnimator.ofFloat(0 ,.85f);

generation of random values
    Random rand = new Random();
    index = rand.nextInt((int) metrics.widthPixels);
    for debugging
    i = Integer.toString(index);
    Log.e(" index is :", i);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener()

        public void onAnimationUpdate(ValueAnimator animation)
            float value = ((Float) (animation.getAnimatedValue())).floatValue();


aniView.setTranslationY((height+ (50*mScale))*value);

keyboard methods goes here

public void onClick(View v)

private void gettext(View v)
        String b = "";
        b = (String) v.getTag();

String img_val = map.get(b);
        int  imgid = (Integer) imageView.getTag();

Log.e("img values=:", img_val+"  "+imgid);

            trying to start the animation again 

I’m using animation.addupdateListener to invoke the animation again and again, but it only calls when the .ofFloat completes the value. When I click the appropriate button, the animation becomes invisible, but the next animation starts again at the same time. I want to start right away.


Basically calling start() again won’t work. You need to somehow “reset” the animation, have you tried calling end() before?


Related Problems and Solutions