Android10打断动画,Android开发(10) 动画(Animation)
概述
Android SDK介紹了兩種Animation:
Tween Animation:通過對場景里的對象不斷做圖像變換(平移、縮放、旋轉)產生動畫效果,即是一種 漸變動畫 ,或者說 補間動畫。
Frame Animation:順序播放事先做好的圖像,是一種畫面轉換動畫,或者說 逐幀動畫。
漸變動畫
4種漸變動畫
alpha 漸變透明度動畫效果
scale 漸變尺寸伸縮動畫效果
translate 畫面轉換位置移動動畫效果
rotate 畫面轉移旋轉動畫效果
實現動畫的步驟:
1.準備一個animation對象,改對象可以看作是個動畫對象,它描述(封裝)了什么樣式的動畫。
我們可以在代碼里手動創建這些對象,對應的4個animaiton對象類:
AlphaAnimation漸變透明度動畫效果
ScaleAnimation漸變尺寸伸縮動畫效果
TranslateAnimation畫面轉換位置移動動畫效果
RotateAnimation畫面轉移旋轉動畫效果
XML方式
我也可以寫一個描述動畫的xml文件,放到資源文件的anim文件夾下。然后,在代碼里加載(load)這個描述的文件:
int animationSrouceId = 0;//資源文件的ID
Animation ani1 = AnimationUtils.loadAnimation(
getApplicationContext(), animationSrouceId);
return ani1;
2.為view視圖控件 指定 啟動動畫,調用startAnimation方法來完成。
//組件播放動畫
ImageView _imageView1;
_imageView1 = (ImageView)findViewById(R.id.imageView1);
_imageView1.start Animation(ani1);
下圖是我做的DEMO截圖,動畫的樣式很難截圖上來。我會在本文末尾放上源代碼。
下面是xml描述的animation動畫
透明alpha效果的代碼:
android:fromAlpha="0.3"
android:toAlpha="1.0"
android:duration="2000"
/>
旋轉(rotate)
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:fromDegrees="0"
android:toDegrees="+350"
android:pivotX="50%"
android:pivotY="50%"
android:duration="3000" />
縮放(scale)
android:interpolator=
"@android:anim/accelerate_decelerate_interpolator"
android:fromXScale="0.0"
android:toXScale="1.4"
android:fromYScale="0.0"
android:toYScale="1.4"
android:pivotX="50%"
android:pivotY="50%"
android:fillAfter="false"
android:duration="700" />
位移(translate )
android:fromXDelta="0"
android:toXDelta="50"
android:fromYDelta="0"
android:toYDelta="50"
android:duration="2000"
android:fillAfter="true"
/>
逐幀動畫演示(Frame Animation)
逐幀動畫就是將多張圖片按順序展示,從而產生一種動態的效果。
效果演示:
1.準備幾張連續的圖片,編寫動畫描述文件(在anim資源文件夾下新建一個XML)。
android:oneshot="true">
2.在窗體里放置一個ImageView 控件,并在代碼里編寫
_imageView1 = (ImageView)findViewById(R.id.imageView1);//放置的ImageView 控件
//設置動畫背景
_imageView1.setBackgroundResource(R.anim.animation_list); //其中R.anim.animation_list就是上一步準備的動畫描述文件的資源名
//獲得動畫對象
_animaition = (AnimationDrawable) _imageView1.getBackground();
3.啟動動畫
_animaition.setOneShot(false); //是否僅僅啟動一次?
if(_animaition.isRunning())//是否正在運行?
{
_animaition.stop();//停止
}
_animaition.start();//啟動
參考
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的Android10打断动画,Android开发(10) 动画(Animation)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 可能存在无限递归_你为什么学不会递归?读
- 下一篇: mysql 插入优化_MySQL批量SQ