Difference Between IsStarted & IsRunning for ValueAnimator

Nathan Sokalski 4,111 Reputation points
2022-12-01T22:56:04.603+00:00

I am creating a Play/Pause button for a ValueAnimator animation. In the handler for the button, I need to determine the current state of the ValueAnimator to determine what method of the ValueAnimator to call. This is my first time using animation in an app. I am trying to determine what properties (IsStarted & IsRunning) to use to determine this, as well as exactly when & what causes them to change (the names sound very similar, so I am trying to understand the difference). I am also unsure when to use which methods to start & stop the ValueAnimator (Resume vs Start, Cancel vs End vs Pause, etc.). I want the user to be able to start & stop at any time (unless the ValueAnimator has finished, another reason I need to know exactly when IsStarted & IsRunning change). I also need a Reset button (is this the purpose of the Cancel method?). Any help would be appreciated.

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,363 questions
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 44,331 Reputation points Microsoft Vendor
    2022-12-05T09:00:06.013+00:00

    Hello,

    The difference between IsStarted and IsRunning is only that IsStarted is true immediately after calling the Start() method, while IsRunning is only true after the animation actually starts. And after IsRunning becomes True, CurrentPlayTime will start timing.

    For example, if I start the animation, call Pause() after 1 minute, and then wait 10 minutes, will CurrentPlayTime be 0:01:00 or 0:11:00?

    The Pause() method does not stop the CurrentPlayTime timer, therefore, the value of it will be 0:11:00. You could verify it by referring to the following code:

       var text = FindViewById<TextView>(Resource.Id.textView1);  
       var animator = ObjectAnimator.OfFloat(text, "translationY", 0, 900);  
       animator.SetDuration(5000);  
       animator.StartDelay = 2000;  
       Button Startbutton = FindViewById<Button>(Resource.Id.button1);  
       Button Pausebutton = FindViewById<Button>(Resource.Id.button2);  
       Button Resumebutton = FindViewById<Button>(Resource.Id.button3);  
       Startbutton.Click += (s, e) =>  
       {  
           animator.Start();  
       };  
       Pausebutton.Click += (s, e) =>  
       {  
           animator.Pause();  
           Console.WriteLine(animator.CurrentPlayTime);  
       };  
       Resumebutton.Click += (s, e) =>  
       {  
           animator.Resume();  
           Console.WriteLine(animator.CurrentPlayTime);  
       };  
    

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.