Android編程中Tween動(dòng)畫和Frame動(dòng)畫實(shí)例分析
本文實(shí)例講述了Android編程中Tween動(dòng)畫和Frame動(dòng)畫實(shí)現(xiàn)方法。分享給大家供大家參考,具體如下:
Animation主要有兩種動(dòng)畫模式:Tween動(dòng)畫和Frame動(dòng)畫
Tween動(dòng)畫由四種類型組成
res目錄下新建anim創(chuàng)建Tween.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <!-- 透明 --> <alpha android:fromAlpha="1" android:toAlpha="0" android:duration="3000" /> <!-- 旋轉(zhuǎn) --> <rotate android:fromDegrees="0" android:toDegrees="360" android:pivotX="50%" android:pivotY="50%" android:duration="3000" /> <!-- 縮放 --> <scale android:fromXScale="1" android:fromYScale="1" android:toXScale="3" android:toYScale="3" android:pivotX="0" android:pivotY="0" android:duration="3000" /> <!-- 移動(dòng) --> <translate android:fromXDelta="0" android:fromYDelta="0" android:toXDelta="50%p" android:toYDelta="50%p" android:duration="3000" /> </set>
以上每個(gè)動(dòng)畫效果可放在不同的xml文件中已方便查看效果
下邊是Activity中調(diào)用動(dòng)畫
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); imageView = (ImageView) findViewById(R.id.img); } public void onClick(View view) { Animation animation = null; switch (view.getId()) { case R.id.alpha: animation = AnimationUtils.loadAnimation(this, R.anim.alpha); break; case R.id.scale: animation = AnimationUtils.loadAnimation(this, R.anim.scale); break; case R.id.translate: animation = AnimationUtils.loadAnimation(this, R.anim.translate); break; case R.id.rotate: //animation = AnimationUtils.loadAnimation(this, R.anim.rotate); //令一種方式JavaCode中 創(chuàng)建RotateAnimation animation = new RotateAnimation(0, 180, RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f); animation.setDuration(3000); break; case R.id.all: animation = AnimationUtils.loadAnimation(this, R.anim.Tween); break; } //啟動(dòng)動(dòng)畫 imageView.startAnimation(animation); }
Tween動(dòng)畫由四種類型組成
幀動(dòng)畫是有多張圖片組成,多張圖片循環(huán)。
示例:
Frame.xml
<?xml version="1.0" encoding="utf-8"?> <animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false"> <item android:drawable="@drawable/p1" android:duration="200" /> <item android:drawable="@drawable/p2" android:duration="200" /> <item android:drawable="@drawable/p3" android:duration="200" /> <item android:drawable="@drawable/p4" android:duration="200" /> <item android:drawable="@drawable/p5" android:duration="200" /> <item android:drawable="@drawable/p6" android:duration="200" /> <item android:drawable="@drawable/p7" android:duration="800" /> <item android:drawable="@drawable/p8" android:duration="200" /> <item android:drawable="@drawable/p9" android:duration="200" /> <item android:drawable="@drawable/p10" android:duration="200" /> <item android:drawable="@drawable/p11" android:duration="200" /> </animation-list>
main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@anim/frame" android:onClick="go" /> </LinearLayout>
Activity:
public void go(View view) { // 獲取ImageView ImageView imageView = (ImageView) view; // 獲取ImageView上面的動(dòng)畫圖片 AnimationDrawable drawable = (AnimationDrawable) imageView.getDrawable(); // 動(dòng)畫開始 drawable.start(); }
希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。
- Android動(dòng)畫之補(bǔ)間動(dòng)畫(Tween Animation)實(shí)例詳解
- Android幀動(dòng)畫、補(bǔ)間動(dòng)畫、屬性動(dòng)畫用法詳解
- Android動(dòng)畫之補(bǔ)間動(dòng)畫(Tween Animation)基礎(chǔ)學(xué)習(xí)
- android 幀動(dòng)畫,補(bǔ)間動(dòng)畫,屬性動(dòng)畫的簡(jiǎn)單總結(jié)
- Android基礎(chǔ)知識(shí)之tween動(dòng)畫效果
- Android Tween動(dòng)畫之RotateAnimation實(shí)現(xiàn)圖片不停旋轉(zhuǎn)效果實(shí)例介紹
- Android動(dòng)畫之漸變動(dòng)畫(Tween Animation)詳解 (漸變、縮放、位移、旋轉(zhuǎn))
- Android 動(dòng)畫之TranslateAnimation應(yīng)用詳解
- Android 動(dòng)畫之ScaleAnimation應(yīng)用詳解
- Android控件Tween動(dòng)畫(補(bǔ)間動(dòng)畫)實(shí)現(xiàn)方法示例
相關(guān)文章
Android中ScrollView監(jiān)聽滑動(dòng)距離案例講解
這篇文章主要介紹了Android中ScrollView監(jiān)聽滑動(dòng)距離案例講解,本篇文章通過簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-08-08android studio的Handler簡(jiǎn)單實(shí)例代碼
今天通過實(shí)例代碼給大家介紹android studio的Handler簡(jiǎn)單用法,代碼簡(jiǎn)單易懂,對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2021-10-10android仿知乎ScrollView滾動(dòng)改變標(biāo)題欄透明度
這篇文章主要為大家詳細(xì)介紹了android仿知乎ScrollView滾動(dòng)改變標(biāo)題欄透明度,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-06-06詳解Android 利用Iptables實(shí)現(xiàn)網(wǎng)絡(luò)黑白名單(防火墻)
這篇文章主要介紹了詳解Android 利用Iptables實(shí)現(xiàn)網(wǎng)絡(luò)黑白名單(防火墻),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-08-08Android實(shí)現(xiàn)日期時(shí)間選擇對(duì)話框
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)日期以及時(shí)間選擇對(duì)話框,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-09-09加載頁(yè)面遮擋耗時(shí)操作任務(wù)頁(yè)面--第三方開源之AndroidProgressLayout
AndroidProgressLayout實(shí)現(xiàn)為界面添加圓形進(jìn)度條。調(diào)用setprogress()方法顯示和隱藏進(jìn)度條,這篇文章主要介紹了加載頁(yè)面遮擋耗時(shí)操作任務(wù)頁(yè)面--第三方開源之AndroidProgressLayout的相關(guān)資料,需要的朋友可以參考下2015-11-11詳解Android?Flutter中SliverAppBar的使用教程
對(duì)于一個(gè)APP來說,肯定會(huì)有一個(gè)AppBar,這個(gè)AppBar一般包含了APP的導(dǎo)航信息等。在lutter已經(jīng)為我們提供了一個(gè)非常強(qiáng)大的AppBar組件,這個(gè)組件叫做SliverAppBar。本文就來聊聊它的具體使用吧2023-01-01