Skip to content

Sweeping second hand animation #5

Description

@ehausen

Hello!

I tried modifying the code so that a sweeping second hand effect could be achieved, similar to expensive watches like Rolex have. I know that I should animate the second hand, but don't quite know how to implement it.

First I tried setting the delay in:
public void setTime(Calendar calendar) { mCalendar = calendar; invalidate(); if (autoUpdate) { new Handler().postDelayed(new Runnable() { @Override public void run() { setTime(Calendar.getInstance()); } }, 1000); } }

to 250 instead of 1000 and modifying the updateHands() slightly so that second hand would update more often. Obviously 250ms was little bit too much and the second hand jumped weirdly.

I realized that animation is a better idea.
I looked at this example: https://stackoverflow.com/questions/13719890/how-to-make-android-sweeping-second-hand-on-analog-clock
but realized this widget is using canvas instead of ImageView and found out that a good way would be to use Matrix while animating. Something similar to this:
https://stackoverflow.com/questions/27832881/animate-rotation-of-an-image-in-android

Unfortunately I can't quite get it to work.
Any suggestions or pointers?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions