Search code examples
androidandroid-layoutandroid-animationandroid-viewandroid-scrollview

Rotate icons/views along a circular path, on scroll - Android


I'm basically trying to implement something similar to this. Sadly, it's an iOS tutorial.

I have googled in most possible keywords to move something in circular manner, but couldn't find any to start off. Can any one atleast provide any hints on how this can be hacked on android? Please.

Thanks.


Solution

  • This would be pretty easy to do in a custom control. Just create a class that extends View and override the draw() method. Then you can listen for touches and calculate how far the user has rotated the control. Then you just need to use that data to rotate the canvas and draw the numbers on it.

    -= Update =- When you override the draw method you get a Canvas object. That object lets you draw to it what ever you want. It would look something like this:

    @Override
    public void draw(Canvas c)
    {
        c.rotate(amount);
        c.drawBitmap(myImage);
    }
    

    This is a link to the full Canvas Documentation.