日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

Android10打断动画,Android开发(10) 动画(Animation)

發布時間:2025/3/11 Android 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。