<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # 1. 插值器Interpolator 前面提到過,在`xml`中使用`android:interpolator`用來指定一個插值器,它會影響動畫的播放速度。系統常見的插值器有: * 線性插值器,`LinearInterpolator`。 * 加速減速插值器:`AccelerateDecelerateInterpolator`。 * 減速插值器:`DecelerateInterpolator`。 這里以`LinearInterpolator`為案例: ~~~java public class LinearInterpolator extends BaseInterpolator implements NativeInterpolator { public LinearInterpolator() { } public LinearInterpolator(Context context, AttributeSet attrs) { } public float getInterpolation(float input) { return input; } /** @hide */ @Override public long createNativeInterpolator() { return NativeInterpolatorFactory.createLinearInterpolator(); } } ~~~ 從代碼可以知道輸入和輸出都是`input`,也就是說斜率為常數。這里舉一個案例,在`40ms`內,使用線性插值器將`View`的`x`從`0`變換到`40`。動畫的刷新頻率為`10ms/幀`,那么我們可以得出下面幾個刷新時刻: | 時間段 | 0 | 1 |2|3|4| | --- | --- |--- |--- |--- |--- | | t | 0ms | 10ms | 20ms | 30ms| 40ms | 具體的`x`變為了什么值,這里就需要使用估值器,比如: ~~~ public class IntEvaluator implements TypeEvaluator<Integer> { /** * This function returns the result of linearly interpolating the start and end values, with * <code>fraction</code> representing the proportion between the start and end values. The * calculation is a simple parametric calculation: <code>result = x0 + t * (x1 - x0)</code>, * where <code>x0</code> is <code>startValue</code>, <code>x1</code> is <code>endValue</code>, * and <code>t</code> is <code>fraction</code>. * * @param fraction The fraction from the starting to the ending values * @param startValue The start value; should be of type <code>int</code> or * <code>Integer</code> * @param endValue The end value; should be of type <code>int</code> or <code>Integer</code> * @return A linear interpolation between the start and end values, given the * <code>fraction</code> parameter. */ public Integer evaluate(float fraction, Integer startValue, Integer endValue) { int startInt = startValue; return (int)(startInt + fraction * (endValue - startInt)); } } ~~~ 也就是傳入當前的百分比,得到估值。計算公式為: ``` result = x0 + t * (x1 - x0) ``` 簡單理解一下也就是起始位置`x0`加上傳入的比例`t`根據其移動距離轉化后的長度值。 那么,類似的這里簡單摘要一下`AccelerateDecelerateInterpolator`的源碼: ~~~ public class AccelerateDecelerateInterpolator extends BaseInterpolator implements NativeInterpolator { public AccelerateDecelerateInterpolator() { } @SuppressWarnings({"UnusedDeclaration"}) public AccelerateDecelerateInterpolator(Context context, AttributeSet attrs) { } public float getInterpolation(float input) { return (float)(Math.cos((input + 1) * Math.PI) / 2.0f) + 0.5f; } } ~~~ 其計算也就是: ![](https://img.kancloud.cn/80/23/8023b8602443109fa379470942f0fe3f_265x105.png) 當然,我們也可以定義自己的插值器。 # 2. 估值器Evaluator 前面我們使用過`ArgbEvaluator`,主要用來計算改變后的百分比對應的值。比如:`IntEvaluator`、`FloatEvaluator`和`ArgbEvaluator`。 上面介紹了`IntEvaluator`,我們知道其計算也就是根據比例來計算值。那么對應的`FloatEvaluator`這里也簡單看下: ~~~ public class FloatEvaluator implements TypeEvaluator<Number> { public Float evaluate(float fraction, Number startValue, Number endValue) { float startFloat = startValue.floatValue(); return startFloat + fraction * (endValue.floatValue() - startFloat); } } ~~~ 可以看到這里的計算和`IntEvaluator`保持一致,只是類型不同。 同樣的,也可以自定義一個估值器來計算。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看