android動畫
我們搞android的都知道android的三類Animation,分別是Tween Animation ,Frame Animation和屬性動畫。
1.frame animation非常的簡單,說白了就是由一張一張的圖片組合而成,首先在drawable文件夾下創建一個類似下面的文件:
<?xml version="1.0" encoding="utf-8"?> <animation-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/ee_1" android:duration="10" /> <item android:drawable="@drawable/ee_2" android:duration="10" /> <item android:drawable="@drawable/ee_3" android:duration="10" /> <item android:drawable="@drawable/ee_6" android:duration="10" /> <item android:drawable="@drawable/ee_7" android:duration="10" /> </animation-list>
然后在java文件中:
AnimationDrawable animationDrawable = (AnimationDrawable) getDrawable(R.drawable.frame_animation); frameAnimation = (TextView) findViewById(R.id.fram_animation); frameAnimation.setBackground(animationDrawable); animationDrawable.start();
就OK了
2.tween animation有四種形式,分別是alpha scale translate rotate ,相信大家都知道什么意思。使用tween animation有兩種方式,一種是使用XML實現,一種是純代碼實現,在開發中我們也沒有必要兩種方式都非常熟悉,只要有一種比較熟就可以了,我個人愛好比較喜歡使用XML。首先創建一個anim文件夾,然后創建一個類似下面的文件:
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:fillAfter="true"http://保持變化后的狀態 > <rotate android:pivotY="50%" android:pivotX="50%" android:fromDegrees="0" android:toDegrees="360" android:duration="1000" android:startOffset="0"http://每一次的間隔時間 android:repeatCount="3"http://重復次數 /> <scale android:pivotY="0" android:pivotX="0" android:fromXScale="1" android:toXScale="0.5" android:fromYScale="1" android:toYScale="0.5" android:duration="1000" /> <translate android:duration="5000" android:fromXDelta="0"http://相對位置 android:fromYDelta="0"http://相對位置 android:toXDelta="700"http://相對位置 android:toYDelta="0"http://相對位置 /> </set>
上述代碼需要注意的地方一標注
然后在java文件中調用:
Animation animation = AnimationUtils.loadAnimation(this,R.anim.tween_animation); animation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { Toast.makeText(getApplicationContext(),"完成",Toast.LENGTH_LONG).show(); } @Override public void onAnimationRepeat(Animation animation) { } }); view.startAnimation(animation);
是不是特別簡單。
關于屬性動畫將在下篇博客中介紹到
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!