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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:11:41+00:00 2026-05-24T12:11:41+00:00

I want to develop my application with a simple animation. I have used a

  • 0

I want to develop my application with a simple animation. I have used a lot of source from: http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/Arcs.html

My code:

 public class Animation extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);        
    setContentView(R.layout.main);
}

private static class AnimView extends View {        
    private Paint myPaint;      
    private Paint myFramePaint;
    private RectF bigOval;
    private float myStart;
    private float mySweep;        
    private static final float SWEEP_INC = 1;

    public AnimView(Context context) {
        super(context);     
        init();
    }

    public AnimView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    private void init() {
        myPaint = new Paint();
        myPaint.setAntiAlias(true);
        myPaint.setStyle(Paint.Style.FILL);
        myPaint.setColor(Color.RED);
        bigOval = new RectF(40, 10, 280, 250);                  
        myFramePaint = new Paint();
        myFramePaint.setAntiAlias(true);
        myFramePaint.setColor(Color.BLACK);
    }

    private void drawArcs(Canvas canvas, RectF oval, boolean useCenter, Paint paint) {
        canvas.drawRect(oval, myFramePaint);
        canvas.drawArc(oval, myStart, mySweep, useCenter, paint);
    }

    @Override
    protected void onDraw(Canvas canvas) {          
        drawArcs(canvas, bigOval, true, myPaint);           
        myStart = -90;          
        mySweep -= SWEEP_INC;
        invalidate();
    }       
}}

I’m using my view in this way in my xml file:

<view
class="go.android.Animation$AnimView"
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
/>

It works properly. I know that it isn’t custom animation. But is this possible to set speed of this animation (in ms or seconds)? Or to stop this animation (for example in the OnClick or OnTouch Listener), and get to know when this animation has finished?

I also want to get first whole circle, and on the end of animation – lack of circle. Simply to change direction of this animation. Is this possible?

I don’t want to use frame-by-frame animation. I want to get continuous animation. Is there any possibilities to get similar animation (with setting speed, etc…)
I also want to animate not only a color but rather a round drawable.

Thank you in advance. Sorry for my English skill.

  • 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-05-24T12:11:42+00:00Added an answer on May 24, 2026 at 12:11 pm

    There might be better and more precise ways to control your animation than this (you could look into using OpenGL), but you can change the speed and direction of the animation relatively easily given your existing code.

    The speed is controlled by the SWEEP_INC field (which stands for Sweep Increment I would guess). Every time the onDraw() method is called, it increases the size of the wedge by 1 degree. If you want the animation to go 5 times as fast, set SWEEP_INC to 5 instead of 1. If you want the animation to go half as fast, set SWEEP_INC to 0.5.

    You can also just set a flag to reverse the animation each time it finishes. I’ve modified your code to reverse each time it reaches the end, using the addToCircle boolean.

    public class Animation extends Activity
    {
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState); 
            setContentView(R.layout.main);
        }
    
        private static class AnimView extends View {        
            private Paint myPaint;      
            private Paint myFramePaint;
            private RectF bigOval;
            private float myStart;
            private float mySweep;        
            private float SWEEP_INC = 1;
            //Use this flag to control the direction of the arc's movement
            private boolean addToCircle = true;
    
            public AnimView(Context context) {
                super(context);     
                init();
            }
    
            public AnimView(Context context, AttributeSet attrs) {
                super(context, attrs);
                init();
            }
    
            private void init() {
                myPaint = new Paint();
                myPaint.setAntiAlias(true);
                myPaint.setStyle(Paint.Style.FILL);
                myPaint.setColor(Color.RED);
                bigOval = new RectF(40, 10, 280, 250);                  
                myFramePaint = new Paint();
                myFramePaint.setAntiAlias(true);
                myFramePaint.setColor(Color.BLACK);
            }
    
            private void drawArcs(Canvas canvas, RectF oval, boolean useCenter, Paint paint) {
                canvas.drawRect(oval, myFramePaint);
                canvas.drawArc(oval, myStart, mySweep, useCenter, paint);
            }
    
            public void setIncrement(float newIncrement)
        {
            SWEEP_INC = newIncrement;
        }
    
            @Override
            protected void onDraw(Canvas canvas) {
                drawArcs(canvas, bigOval, true, myPaint);           
                myStart = -90;
                //If the arc is currently getting bigger, decrease the value of mySweep
                if(addToCircle)
                {
                    mySweep -= SWEEP_INC;
                }
                //If the arc is currently getting smaller, increase the value of mySweep
                else
                {
                    mySweep += SWEEP_INC;
                }
                //If the animation has reached the end, reverse it
                if(mySweep%360 == 0)
                {
                    addToCircle = !addToCircle;
                }
                invalidate();
            }       
        }
    }
    

    EDIT
    If you remove the final and static modifiers from SWEEP_INC you can change the speed of the animation at runtime using the setIncrement(float newIncrement) function I’ve added.

    You can stop the animation by calling setIncrement(0).

    However, I don’t think there is a constant rate at which onDraw is called. So I don’t know of any way to assign a duration in seconds to this animation. For that you may want to look into more sophisticated methods of animation.

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

Sidebar

Related Questions

I am new to Android application development.I want to develop a simple android application
I want to develop an application with simple Quiz-like games (think of a question
Right now, I want to develop a simple application, so I decided that the
I want to develop mysql database application using dbexpress to develop from scratch or
I must develop a simple web application to produce reports. I have a single
I am using this http://imthi.com/blog/programming/iphone-rss-reader-application-with-source-code.php as a start for my rss reader in my
HI all, I want to develop an fake call application in android. After clicking
I want to develop a windows application. If I use native C++ and MFC
I want to develop an iPhone application using the utility template, where the flip
I want to develop a mobile web application using asp.net 3.5 that can be

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.