




下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
信賴源于專業(yè)Android動(dòng)畫開發(fā)技術(shù)信賴源于專業(yè)要解決的問題常見動(dòng)畫分類有哪些?Android中動(dòng)畫實(shí)現(xiàn)的方式有哪些?信賴源于專業(yè)相關(guān)技術(shù)動(dòng)畫原理與分類實(shí)現(xiàn)Tween漸變動(dòng)畫實(shí)現(xiàn)Frame幀動(dòng)畫信賴源于專業(yè)動(dòng)畫實(shí)現(xiàn)Tween漸變動(dòng)畫對(duì)場(chǎng)景中對(duì)象進(jìn)行圖像變換,如平移、縮放、旋轉(zhuǎn)。Frame幀動(dòng)畫順序播放事先做好的圖像,如電影。繪制圖片與動(dòng)畫2D的圖像庫,兩個(gè)包分別是android.graphics.drawable和android.view.animation信賴源于專業(yè)實(shí)現(xiàn)方法Android動(dòng)畫的兩種實(shí)現(xiàn)方法:在XML中配置一個(gè)動(dòng)畫,或者配置多個(gè)動(dòng)畫,然后在代碼中加載,如下代碼所示:拋開XML,在代碼中直接定義一個(gè)動(dòng)畫,如下所示:myAnimation_Alpha=AnimationUtils.loadAnimation(R.anim.alpha_action);AnimationmyAnimation_Alpha=newAlphaAnimation(0.1f,1.0f);信賴源于專業(yè)TweenTween動(dòng)畫效果的變換主要有以下幾種:AlphaAnimation 透明度改變RotateAnimation 旋轉(zhuǎn)ScaleAnimation 縮放TranslateAnimation 平移信賴源于專業(yè)Tween使用XML配置動(dòng)畫時(shí)可以使用如下幾類標(biāo)簽:<alpha> 漸變透明度動(dòng)畫效果<scale> 漸變尺寸伸縮動(dòng)畫效果<translate> 畫面轉(zhuǎn)換位置移動(dòng)動(dòng)畫效果<rotate> 畫面轉(zhuǎn)移旋轉(zhuǎn)動(dòng)畫效果信賴源于專業(yè)TweenXML中配置漸變透明動(dòng)畫效果的代碼fromAlpha/toAlpha屬性為動(dòng)畫起始/結(jié)束時(shí)透明度;透明度的值取0.0-1.0之間的float類型數(shù)據(jù),0.0表示完全透明,1.0表示完全不透明duration
屬性為動(dòng)畫持續(xù)時(shí)間
,毫秒為單位<!--透明--><alphaandroid:fromAlpha=”0.1″android:toAlpha=”1.0″android:duration=”3000″/>信賴源于專業(yè)TweenXML中配置漸變尺寸伸縮動(dòng)畫效果的代碼<!--縮放--> <scaleandroid: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:startOffset=“700” android:duration=”700″/>信賴源于專業(yè)TweenXML中配置漸變尺寸伸縮動(dòng)畫效果accelerate_decelerate_interpolator
是加速-減速動(dòng)畫插入器fromXScale/fromYScale(toXScale/toYScale)動(dòng)畫起始(結(jié)束)時(shí)X、Y坐標(biāo)的伸縮度,0.0表示收縮到?jīng)]有,1.0表示無伸縮,值小于1.0表示收縮,值大于1.0表示放大pivotX[float]/pivotY[float]為動(dòng)畫相對(duì)于物件的X、Y坐標(biāo)的開始位置,從0%-100%中取值信賴源于專業(yè)TweenXML中配置畫面轉(zhuǎn)換位置移動(dòng)動(dòng)畫效果代碼fromXDelta/fromYDelta(toXDelta/toYDelta)動(dòng)畫起始(結(jié)束)時(shí)X,Y坐標(biāo)上的位置<!--平移--><translate
android:fromXDelta="30"
android:toXDelta="-80"
android:fromYDelta="30"
android:toYDelta="300"
android:duration="2000"
/>
信賴源于專業(yè)TweenXML中配置畫面轉(zhuǎn)移旋轉(zhuǎn)動(dòng)畫效果代碼fromDegrees動(dòng)畫起始時(shí)物件的角度,toDegrees動(dòng)畫結(jié)束時(shí)物件旋轉(zhuǎn)的角度,可大于360度,為負(fù)(正)數(shù)表示逆(順)時(shí)針旋轉(zhuǎn)<!--旋轉(zhuǎn)--><rotate android:interpolator=”@android:anim/accelerate_decelerate_interpolator” android:fromDegrees=”0″ android:toDegrees=”+350″ android:pivotX=”50%” android:pivotY=”50%” android:duration=”3000″/>信賴源于專業(yè)TweenJava代碼中直接定義動(dòng)畫的步驟首先,利用AlphaAnimation、RotateAnimation、ScaleAnimation、TranslateAnimationScaleAnimation創(chuàng)建動(dòng)畫接下來,當(dāng)創(chuàng)建完成后,需要用setDuration方法設(shè)置動(dòng)畫的時(shí)間最后,使用startAnimation方法播放動(dòng)畫信賴源于專業(yè)TweenJava代碼中直接定義scale()動(dòng)畫代碼如下publicbooleanscale(){ //創(chuàng)建Scale動(dòng)畫 Scale=newScaleAnimation(0.0f,1.0f,0.0f,1.0f, Animation.RELATIVE_TO_SELF,0.5f, Animation.RELATIVE_TO_SELF,0.5f); //設(shè)置動(dòng)畫的時(shí)間 Scale.setDuration(2000); //開始播放動(dòng)畫 this.startAnimation(Scale); returntrue;}信賴源于專業(yè)TweenJava代碼中直接定義translate()動(dòng)畫如下publicbooleantranslate(){ //創(chuàng)建Translate動(dòng)畫 Translate=newTranslateAnimation(10,150,10,150); //設(shè)置動(dòng)畫的時(shí)間 Translate.setDuration(1000); //開始播放動(dòng)畫 this.startAnimation(Translate); returntrue;}信賴源于專業(yè)代碼實(shí)現(xiàn)Tween動(dòng)畫1/*裝載資源*/BitmapmBitQQmBitQQ=((BitmapDrawable) getResources().getDrawable(R.drawable.qq)).getBitmap();/*繪制圖片*/canvas.drawBitmap(mBitQQ,0,0,null);
/*創(chuàng)建Alpha動(dòng)畫*/privateAnimationmAnimationAlpha=newAlphaAnimation(0.1f,1.0f);/*設(shè)置動(dòng)畫的時(shí)間*/mAnimationAlpha.setDuration(3000);/*開始播放動(dòng)畫*/this.startAnimation(mAnimationAlpha);
/*創(chuàng)建Scale動(dòng)畫*/privateAnimation mAnimationScale =newScaleAnimation(0.0f,1.0f,0.0f,1.0f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);/*設(shè)置動(dòng)畫的時(shí)間*/mAnimationScale.setDuration(500);/*開始播放動(dòng)畫*/this.startAnimation(mAnimationScale);信賴源于專業(yè)代碼實(shí)現(xiàn)Tween動(dòng)畫2/*創(chuàng)建Translate動(dòng)畫*/privateAnimationmAnimationTranslate=newTranslateAnimation(10,100,10,100);/*設(shè)置動(dòng)畫的時(shí)間*/mAnimationTranslate.setDuration(1000);/*開始播放動(dòng)畫*/this.startAnimation(mAnimationTranslate);
/*創(chuàng)建Rotate動(dòng)畫*/privateAnimationmAnimationRotate=newRotateAnimation(0.0f,+360.0f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);/*設(shè)置動(dòng)畫的時(shí)間*/mAnimationRotate.setDuration(1000);/*開始播放動(dòng)畫*/this.startAnimation(mAnimationRotate); 信賴源于專業(yè)代碼實(shí)現(xiàn)Tween動(dòng)畫:main.xml<LinearLayoutxmlns:android=""android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent"><TextViewandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:text="@string/hello"/><Buttonandroid:id="@+id/AlphaAnimation"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="Alpha動(dòng)畫"/><Buttonandroid:id="@+id/ScaleAnimation"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="Scale動(dòng)畫"/><Buttonandroid:id="@+id/TranslateAnimation"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="Translate動(dòng)畫"/><Buttonandroid:id="@+id/RotateAnimation"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="Rotate動(dòng)畫"/></LinearLayout>**
案例AnimationDemo信賴源于專業(yè)XML布局實(shí)現(xiàn)Tween動(dòng)畫/*裝載動(dòng)畫布局*/mAnimationAlpha=AnimationUtils.loadAnimation(mContext,R.anim.alpha_animation);/*開始播放動(dòng)畫*/this.startAnimation(mAnimationAlpha);/*裝載動(dòng)畫布局*/mAnimationScale=AnimationUtils.loadAnimation(mContext,R.anim.scale_animation);this.startAnimation(mAnimationScale);/*裝載動(dòng)畫布局*/mAnimationTranslate=AnimationUtils.loadAnimation(mContext,R.anim.translate_animation);this.startAnimation(mAnimationTranslate);/*裝載動(dòng)畫布局*/mAnimationRotate=AnimationUtils.loadAnimation(mContext,R.anim.rotate_animation);this.startAnimation(mAnimationRotate); 信賴源于專業(yè)R.anim.alpha_animation<setxmlns:android=""><alpha android:fromAlpha="0.1" android:toAlpha="1.0" android:duration="2000"/></set>信賴源于專業(yè)R.anim.scale_animation<setxmlns:android=""><scaleandroid:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:fromXScale="0.0"android:toXScale="1.0"
android:fromYScale="0.0"android:toYScale="1.0"
android:pivotX="50%"android:pivotY="50%"
android:fillAfter="false"android:duration="500"/></set>信賴源于專業(yè)R.anim.translate_animation<setxmlns:android=""><translate android:fromXDelta="10" android:toXDelta="100" android:fromYDelta="10" android:toYDelta="100" android:duration="1000"/></set>信賴源于專業(yè)R.anim.rotate_animation<setxmlns:android=""><rotateandroid:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:fromDegrees="0"android:toDegrees="+360"
android:pivotX="50%"android:pivotY="50%"
android:duration="1000"/></set>**
案例AnimationDemo2信賴源于專業(yè)代碼實(shí)現(xiàn)Frame動(dòng)畫 /*實(shí)例化AnimationDrawable對(duì)象*/ privateAnimationDrawableframeAnimation=newAnimationDrawable(); /*裝載資源*/ //這里用一個(gè)循環(huán)了裝載所有名字類似的資源,如“a1.......15.png”的圖片
for(inti=1;i<=15;i++){ intid=getResources().getIdentifier("a"+i,"drawable", mContext.getPackageName()); DrawablemBitAnimation=getResources().getDrawable(id); /*為動(dòng)畫添加一幀*/ //參數(shù)mBitAnimation是該幀的圖片
//參數(shù)500是該幀顯示的時(shí)間,按毫秒計(jì)算
frameAnimation.addFrame(mBitAnimation,500); } /*設(shè)置播放模式是否循環(huán)false表示循環(huán)而true表示不循環(huán)*/
frameAnimation.setOneShot(false); /*設(shè)置本類將要顯示這個(gè)動(dòng)畫*/ this.setBackgroundDrawable(frameAnimation); /*開始播放動(dòng)畫*/
frameAnimation.start();**案例AnimationDrawableDemo信賴源于專業(yè)XML實(shí)現(xiàn)Frame動(dòng)畫/*定義AnimationDrawable動(dòng)畫對(duì)象*/privateAnimationDrawableframeAnimation=null;/*定義一個(gè)ImageView用來顯示動(dòng)畫*/ImageViewimg=newImageView(mContext);/*裝載動(dòng)畫布局文件*/img.setBackgroundResource(R.anim.frameanimation); /*構(gòu)建動(dòng)畫*/privateAnimationDrawableframeAnimation=(AnimationDrawable)img.getBackground();/*設(shè)置是否循環(huán)*/frameAnimation.setOneShot(false);/*設(shè)置該類顯示的動(dòng)畫*/this.setBackgroundDrawable(frameAnimation);/*開始播放動(dòng)畫*/frameAnimation.start();信賴源于專業(yè)frameanimation.xml<animation-listxmlns:android=""android:oneshot="false"><itemandroid:drawable="@drawable/a1"android:duration="500"/><itemandroid:drawable="@drawable/a2"android:duration="500"/><itemandroid:drawable="@drawable/a3"android:duration="500"/><itemandroid:drawable="@drawable/a4"android:duration="500"/><itemandroid:drawable="@drawable/a5"android:duration="500"/><itemandroid:drawable="@drawable/a6"android:duration="500"/><itemandroid:drawable="@drawable/a7"android:duration="500"/><itemandroid:drawable="@drawable/a8"android:duration="500"/><itemandroid:drawable="@drawable/a9"android:duration="500"/><itemandroid:drawable="@drawable/a10"android:duration="500"/><itemandroid:drawable="@drawable/a11"android:duration="500"/><itemandroid:drawable="@drawable/a12"android:duration="500"/><itemandroid:drawable="@drawable/a13"android:duration="500"/><itemandroid:drawable="@drawable/a14"android:duration="500"/><itemandroid:drawable="@drawable/a15"android:duration="500"/></animation-list>**案例AnimationDrawableDemo2信賴源于專業(yè)Frame在XML中定義Frame動(dòng)畫,每個(gè)節(jié)點(diǎn)定義一幀動(dòng)畫,包括此幀動(dòng)畫的資源和持續(xù)時(shí)間,如下然后在代碼中用方法setBackgroundResource(R.anim.frameanimation)即可裝載布局中定義的動(dòng)畫<animation-list xmlns:android=”” android:oneshot=”true”> <itemandroid:drawable=”@drawable/a1″android:duration=”500″/> <itemandroid:drawable=”@drawable/a2″android:duration=”500″/> <itemandroid:drawable=”@drawable/a3″android:duration=”500″/> <itemandroid:drawable=”@drawable/a4″android:duration=”500″/> <itemandroid:drawable=”@drawable/a5″android:duration=”500″/> </animation-list>信賴源于專業(yè)FrameJava代碼中直接定義Frame動(dòng)畫首先,創(chuàng)建一個(gè)AnimationDrawable對(duì)象來表示Frame動(dòng)畫接下來,通過addFrame方法把圖像的每一幀顯示內(nèi)容添加進(jìn)去即可信賴源于專業(yè)FrameJava代碼中直接定義Frame動(dòng)畫frameAnimation=newAnimationDrawable(); //裝載動(dòng)畫各個(gè)幀for(inti=1;i<=num;i++){ intid=getResources().getIdentifier(name1+i,"drawable",context.getPackageName()); drawable=getResources().get
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 二零二四年12月份半包合同書新風(fēng)主機(jī)減震施工標(biāo)準(zhǔn)
- 2024年十一月無障礙坡道加裝房屋特殊需求合同
- icu護(hù)士年終述職報(bào)告
- 山東省臨沂第三中學(xué)2024-2025學(xué)年高二下學(xué)期3月份月考數(shù)學(xué)試題(原卷版+解析版)
- 2025機(jī)器設(shè)備質(zhì)押合同書
- 樓房轉(zhuǎn)讓合同范本
- 產(chǎn)品委托開發(fā)合同范本
- 通信器材購銷合同
- 物品無償贈(zèng)與合同
- 2025購銷合同協(xié)議書范本
- 《概率論與數(shù)理統(tǒng)計(jì)》課件 概率論
- 2024年河北省廊坊市公開招聘警務(wù)輔助人員(輔警)筆試專項(xiàng)訓(xùn)練題試卷(3)含答案
- 胃腸術(shù)后引流管護(hù)理
- 安全管理人員考試圖片題
- 環(huán)境設(shè)計(jì)專業(yè)的職業(yè)規(guī)劃
- 【MOOC】中央銀行學(xué)-江西師范大學(xué) 中國大學(xué)慕課MOOC答案
- 陜西延長石油集團(tuán)有限責(zé)任公司行測(cè)筆試題庫2024
- Scratch編程-算法教學(xué)課件4.身體質(zhì)量指數(shù)(BMI)測(cè)試器
- 印章管理責(zé)任承諾書4篇
- 事故隱患報(bào)告和獎(jiǎng)勵(lì)制度
- 新建項(xiàng)目員工四新培訓(xùn)
評(píng)論
0/150
提交評(píng)論