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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:18:47+00:00 2026-05-20T00:18:47+00:00

I am trying to perform basic task of rotating a canvas 20 times a

  • 0

I am trying to perform basic task of rotating a canvas 20 times a
second using timer but it doesn’t seem to be working properly and its
lagging. for example, if I rotate rectangle 0.3 degrees per 50 ms it
should rotate 6 degree in on second, but that is not the case. It
really slow in rotation. Here is my sample code:

//Code for update task
class UpdateTimeTask extends TimerTask {

      public void run() {
              hndView.post(new Runnable() {
                   public void run() {
                           hndView.invalidate(); //this code invalidates custom view that calls onDraw to draw rotated hand
                   }
                 });
      }
}


//Code for onDraw method of custom view that needs to be update
@Override 
protected void onDraw(Canvas canvas){

    super.onDraw(canvas);

    //ang is angle to rotate and inc is float value of 0.3 degree to be incremented
    ang = ang + inc;
    if (ang >= 360) ang = ang - 360;
    canvas.rotate(ang, canvas.getWidth()/2, canvas.getHeight()/2);  
    canvas.drawRect((canvas.getWidth()/2 - 2), (canvas.getHeight()/2 - 125), (canvas.getWidth()/2 + 2), (canvas.getHeight()/2 + 10), mTextPaint);
    canvas.restore();

}

//code to schedule task
Timer timer = new Timer();
UpdateTimeTask tt = new UpdateTimeTask();
timer.schedule(tt, 0, 50);

Can anyone please tell me what am I doing wrong here? Should I used
different approach to perform this task? Because its hard to believe
that you cannot have simple smooth rotation of rectangle 20 times in
one second.

  • 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-20T00:18:47+00:00Added an answer on May 20, 2026 at 12:18 am

    I believe you are not using a SurfaceView.

    Drawing like that to a canvas was meant for controls and not fast rendering(read >10fps)

    If you want performance you need either to use a SurfaceView where you’ll average a 25-30 fps or opengl

    Please read : http://developer.android.com/guide/topics/graphics/index.html

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

Sidebar

Related Questions

I am trying to perform the following fadeIn/fadeOut action within the jQuery $.post function.
I am trying to perform a check on individual nodes of an XML file,
I am trying to perform SET operations in Oracle across remote databases. I am
I'm trying to create a flexible security infrastructure for our WCF services on our
I'm trying to create a script that will delete all user properties for a
Really stupid C question. I'm trying to build the source code here so I
I have a GridControl which I populate using a BackgroundWorker . Then I'm using
I want a timer tick/elapsed event inside a new thread. It seems like I
Here's the scenario: ASP.NET MVC2 Web Application Entity Framework 4 (Pure POCO's, Custom Data
Pretty much all the apps I use on a regular basis implement this 'seemly

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.