<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>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                # 1. 屬性動畫 屬性動畫可以作用于任意對象,而不僅僅局限在`View`。同時也支持更多的動畫,而不只是四種動畫效果。 * 動畫默認間隔`300ms`,默認幀率`10ms/幀`。 * 但是是`API 11`(對應`Android 3.0`)之后才支持的,所以如果要兼容之前的版本還需要做處理。 * 在屬性動畫中,比較常見的動畫類有:`ValueAnimator`、`ObjectAnimator`和`AnimatorSet`。`ObjectAnimator`繼承自`ValueAnimator`。 # 2. 簡單使用(動態代碼方式) ## 2.1 平移 將按鈕向下平移高度個距離: ~~~ btn.setOnClickListener { ObjectAnimator.ofFloat(it, "translationY", 1f*it.height) .start() } ~~~ ## 2.2 漸變 將按鈕的背景色設置為一個漸變,重復: ~~~ btn.setOnClickListener { val colorAnim = ObjectAnimator.ofInt( it, "backgroundColor", 0xFFFF8080.toInt(), 0xFF8080FF.toInt() ) colorAnim.apply { duration = 500 repeatCount = ValueAnimator.INFINITE setEvaluator(ArgbEvaluator()) repeatMode = ValueAnimator.REVERSE } colorAnim.start() } ~~~ ## 2.3 動畫集 ~~~ // true,代表使用默認的interpolator val animationSet = AnimationSet(true) // 透明度 0-1 val alphaAnimation = AlphaAnimation(0f, 1f) // 旋轉 val rotateAnimation = RotateAnimation(0f, 90f) // 放大 val scaleAnimation = ScaleAnimation(1f, 1.2f, 1f, 1.2f) animationSet.apply { addAnimation(alphaAnimation) addAnimation(rotateAnimation) addAnimation(scaleAnimation) duration = 5000 interpolator = AccelerateDecelerateInterpolator() fillAfter = true } btn.setOnClickListener { it.startAnimation(animationSet) } ~~~ ## 2.4 對任意屬性修改 值得注意的是,在`View`動畫中只能完成簡單的平移、旋轉、縮放和透明度變換。如果我們希望修改一個按鈕的寬度,那么他是做不到的。這里我們可以使用屬性動畫輕松做到: ~~~ val animator = ObjectAnimator.ofInt(btn, "width", 700) btn.setOnClickListener { animator.start() } ~~~ 對于`TextView`,我們做類似的處理: ~~~ <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" android:textColor="@color/black" android:textSize="24sp" android:background="@color/teal_200" android:gravity="center" /> ~~~ 然后關聯: ~~~ val textViewAnimator = ObjectAnimator.ofInt(textView, "width", 700) textView.setOnClickListener { textViewAnimator.start() } ~~~ 同樣的也有對應的效果。 # 3. xml方式 文件需要定義在`res/animator`目錄下,比如`attranimator01.xml`: ~~~ <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:ordering="sequentially" > <objectAnimator android:propertyName="backgroundColor" android:duration="2000" android:valueFrom="0xffffff00" android:valueTo="0xff00ff00" android:valueType="intType" android:repeatCount="infinite" android:repeatMode="reverse" /> </set> ~~~ 然后關聯: ~~~ val loadAnimator = AnimatorInflater.loadAnimator(this, R.animator.attranimator01) loadAnimator.setTarget(btn) btn.setOnClickListener { loadAnimator.start() } ~~~ # 4. ValueAnimator 注意到上面提到了`ObjectAnimator`繼承自`ValueAnimator`,那么為什么我們前面沒有使用`ValueAnimator`,而只涉及到`ObjectAnimator`類?因為`ValueAnimator`只是對一個值做動畫,如果我們將`ValueAnimator`直接用來做動畫沒有任何效果產生,因為還沒有對應的修改對象的屬性。 那么如果我們能夠監聽到`ValueAnimator`中值得變化,然后我們將其值應用到對應的對象的屬性上,那么就回產生對應的效果。 # 5. 對比 ## anim文件夾 `anim`文件夾下存放補間動畫(即`View`動畫);`xml`文件里只有`scale`、`rotate`、`translate`、`alpha`、`set`五個標簽, 使用方法: 1. 加載動畫:`animation = AnimationUtils.loadAnimation(R.anim.xxx)` 2. 設置動畫:`mView.setAnimation(animation)` 3. 開啟動畫:`mView.startAnimation()` ## animator文件夾 `animator`文件夾下存放屬性動畫,`xml`文件里有`animator`、`objectAnimator`、`set`三個標簽, 使用方法: 1. 加載動畫:`animation = AnimatorInflater.loadAnimator(R.animator.xxx)` 2. 設置動畫:`animation.setTarget(mView)` 3. 開啟動畫:`animation .start()` # 6. 注意 在屬性動畫中,有一種動畫為無限循環動畫,這類動畫需要在`Activity`退出時及時停止,否則可能導致當前`Activity`內存得不到釋放,造成內存泄漏。且對于屬性動畫做一系列變換后,事件觸發位置在控件位置;但是`View`動畫變換后,還是原來位置會觸發事件。這是因為屬性動畫在任何屬性發生變化后,`View`都會自動調用`invalidate()`來繪制。而`View`所做的簡單的平移、旋轉、透明度和縮放僅僅是作用在視圖,其位置屬性不變。
                  <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>

                              哎呀哎呀视频在线观看