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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:50:43+00:00 2026-05-13T23:50:43+00:00

I would like to animate movement on a SurfaceView . Ideally I would like

  • 0

I would like to animate movement on a SurfaceView . Ideally I would like to also be notified once the animation had finished.

For example:
I might have a car facing North. If I wanted to animate it so that it faces South for a duration of 500ms, how could I do that?

I am using a SurfaceView so all animation must be handled manually, I don’t think I can use XML or the android Animator classes.

Also, I would like to know the best way to animate something continuously inside a SurfaceView (ie. a walk cycle)

  • 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-13T23:50:43+00:00Added an answer on May 13, 2026 at 11:50 pm

    Rotating images manually can be a bit of a pain, but here’s how I’ve done it.

    private void animateRotation(int degrees, float durationOfAnimation){
        long startTime = SystemClock.elapsedRealtime();
        long currentTime;
        float elapsedRatio = 0;
        Bitmap bufferBitmap = carBitmap;
    
        Matrix matrix = new Matrix();
    
        while (elapsedRatio < 1){
            matrix.setRotate(elapsedRatio * degrees);
            carBitmap = Bitmap.createBitmap(bufferBitmap, 0, 0, width, height, matrix, true);
            //draw your canvas here using whatever method you've defined
            currentTime = SystemClock.elapsedRealtime();
            elapsedRatio = (currentTime - startTime) / durationOfAnimation;
        }
    
        // As elapsed ratio will never exactly equal 1, you have to manually draw the last frame
        matrix = new Matrix();
        matrix.setRotate(degrees);
        carBitmap = Bitmap.createBitmap(bufferBitmap, 0, 0, width, height, matrix, true);
        // draw the canvas again here as before
        // And you can now set whatever other notification or action you wanted to do at the end of your animation
    
    }
    

    This will rotate your carBitmap to whatever angle you specify in the time specified + the time to draw the last frame. However, there is a catch. This rotates your carBitmap without adjusting its position on screen properly. Depending on how you’re drawing your bitmaps, you could end up with your carBitmap rotating while the top-left corner of the bitmap stays in place. As the car rotates, the bitmap will stretch and adjust to fit the new car size, filling the gaps around it with transparent pixels. It’s hard to describe how this would look, so here’s an example rotating a square:

    alt text

    The grey area represents the full size of the bitmap, and is filled with transparent pixels. To solve this problem, you need to use trigonometry. It’s a bit complicated… if this ends up being a problem for you (I don’t know how you’re drawing your bitmaps to the canvas so it might not be), and you can’t work out the solution, let me know and I’ll post up how I did it.

    (I don’t know if this is the most efficient way of doing it, but it works smoothly for me as long as the bitmap is less than 300×300 or so. Perhaps if someone knows of a better way, they could tell us!)

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

Sidebar

Related Questions

I have two views, jumpBarPortrait and jumpBarLandscape I would like to animate between the
I would like to animate my subviews movement when rotating the device, changing the
So I have a ActivityGroup, and I would like to animate the transition between
I have a really large PNG file that I would like to animate over
I have an NSArray of strings that I would like to animate with a
I have a UIView that I would like to animate into the screen in
I would like to animate nsmenuitem that I have for my app (preferably use
I have a UIView that I would like to animate a flip up. This
I have some 3D character model, and I would like to animate them, to
I have an SVG and I would like to animate a gradient stop from

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.