Android中xml設定Animation動畫效果詳解

來源:互聯網
上載者:User

標籤:

在 Android 中, Animation 動畫效果的實現可以通過兩種方式進行實現,一種是 tweened animation 漸層動畫,另一種是 frame by frame animation 畫面轉換動畫,接下來eoe進行講解。

tweened animation 漸層動畫有以下兩種類型:

1.alpha   漸層透明度動畫效果

2.scale   漸層尺寸伸縮動畫效果

frame by frame animation 畫面轉換動畫有以下兩種類型:

1.translate  畫面轉換位置移動動畫效果

2.rotate    畫面轉移旋轉動畫效果

在 res 檔案夾下建立一個 anim 的檔案夾,並在其中建立一個 animation.xml 檔案,具體如下:

                         xmlns:android="http://schemas.android.com/apk/res/android">                                          android:fromXDelta="0"              // 設定動畫開始時 x 座標的位置                        android:toXDelta="-100%p" // 設定動畫結束時 x 座標的位置                       android:duration="300"        // 設定動畫持續的時間 300 毫秒                 >                                                      android:fromAlpha="1.0"            // 設定動畫開始時的透明度   1.0 代表不透明                        android:toAlpha="0.0"   // 設定動畫開始時的透明度   0.0 表示完全透明                        android:duration="300" // 設定動畫持續的時間 300 毫秒                 />                                  android:interpolator="              // 設定動畫出入器          @android:anim/accelerate_decelerate_interpolator"                    android:fromXScale="0.0"       // 設定動畫開始時 x 座標上的伸縮長度                    android:toXScale="1.4"            // 設定動畫結束時 x 座標上的伸縮長度                    android:fromYScale="0.0"       // 設定動畫開始時 y 座標上的伸縮長度                    android:toYScale="1.4"     // 設定動畫開始時 y 座標上的伸縮長度                    android:pivotX="50%"      // 設定動畫相對於控制項的 x 座標的位置                    android:pivotY="50%"      // 設定動畫相對於控制項的 y 座標的位置                    android:fillAfter="false"    // 該動畫轉化在動畫結束前開始應用                    android:duration="700" // 設定動畫持續的時間          />                              android:interpolator=            // 設定動畫出入器          "@android:anim/accelerate_decelerate_interpolator"                  android:fromDegrees="0"     // 設定動畫開始時的角度                  android:toDegrees="+350"           // 設定動畫結束時的旋轉角度                 android:pivotX="50%"         // 設定動畫相對於控制項的 x 座標的位置                  android:pivotY="50%"         // 設定動畫相對於控制項的 y 座標的位置                  android:duration="3000"       // 設定動畫持續的時間              />                利用 AnimationUtils.loadAnimation 將動畫載入。    Animation animation;            animation=AnimationUtils.loadAnimation(this, R.anim.animation);           // 然後再想要實現動畫效果的控制項上通過使用 startAnimation() 方法進行添加。            // 編寫動畫對象,並且擷取自定應的動畫樣式            animation=AnimationUtils.loadAnimation(this, R.anim.animation);                  spinner.setOnTouchListener(new Spinner.OnTouchListener() {                                                             @Override                               public boolean onTouch(View v, MotionEvent event) {                                      // TODO Auto-generated method stub                                      // 運行動畫 animation                                      v.startAnimation(animation);                                      // 將 spinner 的可見度設定為不可見狀態                                      v.setVisibility(View.INVISIBLE);                                      return false;                               }                        });  

Android中xml設定Animation動畫效果詳解

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.