English 中文(简体)
如何采用横向递减计时器?
原标题:How does one implement a horizontally scrolling countdown timer?
  • 时间:2012-04-12 21:01:22
  •  标签:
  • android

Goal I d like to implement a countdown timer that just scrolls numbers (not graphics) from left to right.

Effect The effect would look like the number zooms in from the left, slows down towards the middle, and then zooms off to the right.

Notes Since I m already using a TimerTask to execute code every second, I could use that to trigger the next number to scroll across the horizontally-scrolling textview.

能否在一次滚动式调查中作为案文加以落实? 寻找从......开始的编码样本。

最佳回答

使用图象是最简单的解决办法。 您可创建自己的或尝试,并结合多个网站 :TranslateAnimations>/strong>。

这将意味着将每一数字放在自己的文本意见中,而不是使用滚动观点。

然后,你可以控制中间的加速度,使用<>Interpolator。 国际刑警组织人员正在如何缓解安乐施。 您可能希望<>。 加速效应/放慢效应。

您可使用<>AnimationSet,对同一观点适用多种分析。 展示如何汇集一个好的阿尼松森Set将是该项目中最具挑战性的一部分。 确保注意“填充”财产。 事实上,在玩 playing后,我认为,习惯的估算比使用已准备好的估算更为简单。

https://github.com/pajtai/CountDown/“rel=“nofollow” 4月17日,在我使用多处预言之前,我做了总结。 如果你看一下最新版本,你就会看到习俗的估算。

每次算术的时间在你确定一次算术的期限之后,就自行决定。 A <Handler ,在前一次完稿之后打下一个号码。 我认为,这比要求每十秒都要求一项职能来更新所有内容,没有什么意义。

职能大纲:

  • An Activity (CountDownActivity.java) over sees everything.
    • The Activitiy s layout XML has a button that is used to start the count down.
    • Once the countdown starts, the button disappears. It reappears when the count down is done.
  • The Activity contains a Handler (MotionHandler.java). The Handler controls the movement and timing of the numbers.
    • The Handler uses a AnimationSet to move the numbers
      • The AnimationSet is a passed in dependency
        • This is for flexibility. Simply pass in a different AnimationSet to change how the numbers move
        • The AnimationSet is made of four Animations a custom Animation (see below)
    • The AnimationSet uses a shared AccelerateDecelerateInterpolator, which seems to work decently. There are other options, including writing your own.
    • The Handler uses a delayed message to start the next number
    • The Handler notifies the Activity when the count down is done using a custom listener (MotionHandler >> CountdownListener)
  • Rotating the device will restart the count down.

注 - 此前,我曾用四张已准备好的阿尼丁松语,我已编辑,仅包括一种习俗。 你可以将其算法推给你的灵魂。

这一习俗的估算使用了Cyclvil,使数字大为小。

/**
 * 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);
    }
}
问题回答

rel=“nofollow”> Easing将有助于你控制速度。





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签