How to implement a horizontal countdown timer?

Goal I would like to implement a countdown timer that simply scrolls numbers (not graphs) from left to right.

Effect The effect will look as if the number increased on the left, it slowed down to the middle and then decreased to the right.

Notes Since I already use TimerTask to execute code every second, I could use this to call the next number to scroll horizontally through the text.

Could this be implemented as a text box inside a scroll? Looking for sample code to start with ....

+5
source share
2 answers

. TranslateAnimations ScaleAnimations.

TextView .

Interpolator. - , Android . , AccelerateDecelerateInterpolator / .

AnimationSet, . , AnimationSet, . "". , , , , .

GitHub, . 17 , . , .

, . A Handler . , , X , .

:

. AnimationSet, , ... .

Cycloid, .

/**
 * A custom animation to move and scale the numbers.
 * 
 */
public class NumberAnimation extends Animation
{
    final public static float MINIMUM = 3;
    private int mHorizontal;
    private int mScaling;

    public NumberAnimation(int horizontalMovement, int scaling)
    {
        mHorizontal = horizontalMovement;
        mScaling = scaling;
    }

    @Override
    protected void applyTransformation(float interpolatedTime, Transformation t)
    {
        // Cycloid repeats every 2pi - scale interpolatedTime to that
        double time = 2 * Math.PI * interpolatedTime;
        // Cycloid function
        float currentScale = (float) (mScaling * (1 - Math.cos(time))) + MINIMUM;
        Matrix matrix = t.getMatrix();
        matrix.preScale(currentScale, currentScale);
        matrix.postTranslate(mHorizontal * interpolatedTime, 0);
    }
}
+9
0

All Articles