【问题标题】:How to simulate an analog stop watch in Android Watch Face?如何在 Android Watch Face 中模拟模拟秒表?
【发布时间】:2018-11-03 01:43:39
【问题描述】:

我正在使用 Android Wear OS 开发一款逼真的计时手表。我已经有一个运行良好的秒针手表和一个停止计时的指针。当我点击手表时,我希望我的计时指针从零开始,但它是从实际秒开始。

我的问题是:如何在我的计时码表旋转中应用移位值以减少实际秒数,并且指针从 0 位置开始?

这是实际行为:

这是旋转小秒针的代码:

private float getSecondsRotation() {
            final float seconds =
                    (mCalendar.get(Calendar.SECOND) + mCalendar.get(Calendar.MILLISECOND) / 1000f);
            return seconds * 6f;
        }

有没有办法为该方法传递shift 参数并从结果中获得折扣?

【问题讨论】:

    标签: android-wear-2.0 watch-face-api


    【解决方案1】:

    我实际上并没有尝试运行此代码,但希望它能让您了解如何解决您的问题。

    // True when the chronograph is running, false otherwise
    private boolean isChronographRunning = false;
    
    // The second when the chronograph is started
    private float secondOffset = 0f;
    
    // Called when the user taps on the watch face
    private void startChronograph() {
        isChronographRunning = true;
        secondOffset = mCalendar.get(Calendar.SECOND) + mCalendar.get(Calendar.MILLISECOND) / 1000f;
    }
    
    // Called from your draw loop if(isChronographRunning)
    private float getChronographRotation() {
        float currentSecond = mCalendar.get(Calendar.SECOND) + mCalendar.get(Calendar.MILLISECOND) / 1000f;
        float chronographSecond = currentSecond - secondOffset;
        return chronographSecond * 6f;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-23
      • 2012-05-15
      • 2020-06-02
      • 2015-01-27
      • 1970-01-01
      相关资源
      最近更新 更多