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 8522759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:13:00+00:00 2026-06-11T07:13:00+00:00

I’ve defined RotateAnimation to rotate a ImageView . So, I want to stop the

  • 0

I’ve defined RotateAnimation to rotate a ImageView. So, I want to stop the animation after some repeats. The scenario is as following :

First animation starts from -25 to 25 degree, after one animating, this should be change to -24 to 24 and reversely and … and when reach to 0 to 0 this should be cancel.

    int intervalSize = -25;

    RotateAnimation r = new RotateAnimation(intervalSize, intervalSize, pivotX, pivotY);
    r.setDuration(3000);
    r.setStartOffset(0);
    r.setRepeatMode(RotateAnimation.REVERSE);
    r.setRepeatCount(RotateAnimation.INFINITE);
    startAnimation(r);
    r.setAnimationListener(new AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationRepeat(Animation animation) {
            if (intervalSize == 0)
                animation.cancel();
            intervalSize--;
        }

        @Override
        public void onAnimationEnd(Animation animation) {

        }
    });

Could any one please how can I reach to this ?

Thanks in advance‌:)

  • 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-11T07:13:01+00:00Added an answer on June 11, 2026 at 7:13 am

    I think your problem is that while you ARE changing your global var interval size upon each animation repeat, the animation that is being repeated is not looking at your var, but rather the primitive ints that were passed to it when you said: new RotateAnimation(intervalSize, intervalSize, pivotX, pivotY);

    That is, the animation will always have -25 since that’s what it was constructed with, it doesnt care or know about the subsequent changes to your intervalSize var.

    To achieve what you want ideally you’d be able to do something like:

     @Override
            public void onAnimationRepeat(Animation animation) {
                if (intervalSize == 0){
                    animation.cancel();
                } else {
                  ((RotationAnimation)animation).setFromDegress(intervalSize);
                  ((RotationAnimation)animation).setToDegress(intervalSize);
                }
            }
    

    But alas, it doesnt look like there are setter methods for those attributes on RotationAnimation. So that leaves you with the possibility of using the onAnimationEndEvent to create a new Animation with the new intervalSizeValue. As in:

    Use onAnimationEnd event and rather than have a repeating animation, have a one time animation. Once it ends, the onAnimationEnd event should construct a new RotationAnimation with your new intervalSize.

    Here is a working example that animates the textview from the typical Android HelloWorld app in the way you specify:

     package com.example.rotationtest;
    
    import android.os.Bundle;
    import android.app.Activity;
    import android.view.ViewTreeObserver.OnGlobalLayoutListener;
    import android.view.animation.Animation;
    import android.view.animation.Animation.AnimationListener;
    import android.view.animation.RotateAnimation;
    import android.widget.TextView;
    
    public class MainActivity extends Activity {
        private TextView tv;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState); 
            setContentView(R.layout.activity_main);
    
            // the textView we will rotate
            tv = (TextView) this.findViewById(R.id.textView1);
    
            /***
             * we want to have the correct measured size of the view we are going to animate
             * as we want to do a rotation around it's centerpoint.
             * But, we cant get the measured size of a view until Layout has happened...
             * So use a LayoutListener to know when layout is done
             * But, beware that this is often called back on more than once,
             * so remove the listener after it is called first time
             */
            tv.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    initAnimation();
                    tv.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                    // above is deprecated. in API16+ use tv.getViewTreeObserver().removeOnGlobalLayoutListener(this);      
                }
            });
        }
    
        private int mRotationAbsDegrees = 25;
        private int mCurrentFromDegrees;
        private int mCurrentToDegrees;
    
        private void initAnimation(){
        mCurrentFromDegrees = -1 * mRotationAbsDegrees;
        mCurrentToDegrees = mRotationAbsDegrees;
        makeNewAnimation();
        }
    
        private void makeNewAnimation(){
        RotateAnimation r = new RotateAnimation(mCurrentFromDegrees, mCurrentToDegrees,  tv.getMeasuredWidth()/2, tv.getMeasuredHeight()/2);
            r.setDuration(3000); // TODO: might want to reduce the time as we get closer to zero mRotationAbsDegrees
            r.setStartOffset(0);
            //r.setRepeatMode(RotateAnimation.REVERSE);
            //r.setRepeatCount(RotateAnimation.INFINITE);
            tv.startAnimation(r);
            r.setAnimationListener(new AnimationListener() {
    
                @Override public void onAnimationStart(Animation animation) {}
    
                @Override public void onAnimationRepeat(Animation animation) {}
    
                @Override
                public void onAnimationEnd(Animation animation) {
                // if we have run down the mRotationAbsDegrees to zero, stop animating
                if (mRotationAbsDegrees <= 0){
                    return;
                }
                if (mCurrentFromDegrees < 0){
                    // reverse the from to
                    mCurrentFromDegrees = -1*mCurrentFromDegrees;
                    mCurrentToDegrees  = -1*mCurrentToDegrees;
                } else {
                    // reduce the mRotationAbsDegrees
                    mRotationAbsDegrees--;
                    mCurrentFromDegrees = -1 * mRotationAbsDegrees;
                    mCurrentToDegrees = mRotationAbsDegrees;
                }
                makeNewAnimation();
                }
            });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

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.