Android - need a number flip animation

2019-03-21 11:51发布

问题:

I'm developing an Android application to read "electric meters". The user enters the counter - the application calculates the consumption and sends it to a server.

The representation of the counter should look like a old electricity meters old electricity meter

I've already integrated the counter-numbers as images. I will have an animation that if the user enters a number (keyboard) then the relevant section begins to rotate to the correct number position.

For example: The user enters the number 5 for the first digit, then rotate the digit from 0-5. The animated numbers flip to the correct position. How can I do this? Any idea? thank u!!!

回答1:

There is a custom view which I've created for a custom application. Initially, i also tried searching for this type of view but couldn't found any. So created one of my own.

You can see the code here: https://github.com/Vinayrraj/Android-FlipDigitView

Also this video might help you: http://youtu.be/d6-M2nN2Gzg



回答2:

You can take a look to Ticker, an Android text view with scrolling text change animation:

Ticker is a simple Android UI component for displaying scrolling text. Think about how an odometer scrolls when going from one number to the next, that is similar to what Ticker does. The Ticker handles smooth animations between strings and also string resizing (e.g. animate from "9999" to "10000").



回答3:

I'd have one spinning animation - but make it fast and blurred so you can't see what number it's on - play that for 1 second, then replace with the correct position - it's a trick, but will save you doing lots of different animations.



回答4:

If I got your need, I would use two different approach: 1) one big animation with numbers from 0 to 9; when you have an inoput number, you should launch the animation and stop at the right frame (just a math calculation matter); 2) one animation for each number; you could think about a number flipping as if its rotating on itself vertically; then, when the user put his number X, you have to flip between X different animations until the good one and stop.