詳談Android動(dòng)畫效果translate、scale、alpha、rotate
動(dòng)畫類型
Android的animation由四種類型組成
XML中
alpha | 漸變透明度動(dòng)畫效果 |
scale | 漸變尺寸伸縮動(dòng)畫效果 |
translate | 畫面轉(zhuǎn)換位置移動(dòng)動(dòng)畫效果 |
rotate | 畫面轉(zhuǎn)移旋轉(zhuǎn)動(dòng)畫效果 |
JavaCode中
AlphaAnimation | 漸變透明度動(dòng)畫效果 |
ScaleAnimation | 漸變尺寸伸縮動(dòng)畫效果 |
TranslateAnimation | 畫面轉(zhuǎn)換位置移動(dòng)動(dòng)畫效果 |
RotateAnimation | 畫面轉(zhuǎn)移旋轉(zhuǎn)動(dòng)畫效果 |
Android動(dòng)畫模式
Animation主要有兩種動(dòng)畫模式:
一種是tweened animation(漸變動(dòng)畫)
XML中 | JavaCode |
alpha | AlphaAnimation |
scale | ScaleAnimation |
一種是frame by frame(畫面轉(zhuǎn)換動(dòng)畫)
XML中 | JavaCode |
translate | TranslateAnimation |
rotate | RotateAnimation |
Android動(dòng)畫解析
alpha xml 淡出效果
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <alpha android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="500" /> </set> <!-- fromAlpha:開始時(shí)透明度 toAlpha: 結(jié)束時(shí)透明度 duration:動(dòng)畫持續(xù)時(shí)間 -->
alpha xml 淡入效果
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="500" /> </set> <!-- fromAlpha:開始時(shí)透明度 toAlpha: 結(jié)束時(shí)透明度 duration:動(dòng)畫持續(xù)時(shí)間 -->
rotate.xml 旋轉(zhuǎn)效果:
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <rotate android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:fromDegrees="300" android:toDegrees="-360" android:pivotX="10%" android:pivotY="100%" android:duration="10000" /> </set> <!-- fromDegrees 動(dòng)畫開始時(shí)的角度 toDegrees 動(dòng)畫結(jié)束時(shí)物件的旋轉(zhuǎn)角度,正代表順時(shí)針 pivotX 屬性為動(dòng)畫相對(duì)于物件的X坐標(biāo)的開始位置 pivotY 屬性為動(dòng)畫相對(duì)于物件的Y坐標(biāo)的開始位置 -->
scale.xml 縮放效果:
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <scale android:interpolator= "@android:anim/decelerate_interpolator" android:fromXScale="0.0" android:toXScale="1.5" android:fromYScale="0.0" android:toYScale="1.5" android:pivotX="50%" android:pivotY="50%" android:startOffset="0" android:duration="10000" android:repeatCount="1" android:repeatMode="reverse" /> </set> <!-- fromXDelta,fromYDelta 起始時(shí)X,Y座標(biāo),屏幕右下角的座標(biāo)是X:320,Y:480 toXDelta, toYDelta 動(dòng)畫結(jié)束時(shí)X,Y的座標(biāo) --> <!-- interpolator 指定動(dòng)畫插入器 常見的有加速減速插入器 accelerate_decelerate_interpolator 加速插入器 accelerate_interpolator, 減速插入器 decelerate_interpolator。 fromXScale,fromYScale, 動(dòng)畫開始前X,Y的縮放,0.0為不顯示, 1.0為正常大小 toXScale,toYScale, 動(dòng)畫最終縮放的倍數(shù), 1.0為正常大小,大于1.0放大 pivotX, pivotY 動(dòng)畫起始位置,相對(duì)于屏幕的百分比,兩個(gè)都為50%表示動(dòng)畫從屏幕中間開始 startOffset, 動(dòng)畫多次執(zhí)行的間隔時(shí)間,如果只執(zhí)行一次,執(zhí)行前會(huì)暫停這段時(shí)間, 單位毫秒 duration,一次動(dòng)畫效果消耗的時(shí)間,單位毫秒, 值越小動(dòng)畫速度越快 repeatCount,動(dòng)畫重復(fù)的計(jì)數(shù),動(dòng)畫將會(huì)執(zhí)行該值+1次 repeatMode,動(dòng)畫重復(fù)的模式,reverse為反向,當(dāng)?shù)谂即螆?zhí)行時(shí),動(dòng)畫方向會(huì)相反。 restart為重新執(zhí)行,方向不變 -->
translate.xml 移動(dòng)效果:
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromXDelta="320" android:toXDelta="0" android:fromYDelta="480" android:toYDelta="0" android:duration="10000" /> </set> <!-- fromXDelta,fromYDelta 起始時(shí)X,Y座標(biāo),屏幕右下角的座標(biāo)是X:320,Y:480 toXDelta, toYDelta 動(dòng)畫結(jié)束時(shí)X,Y的座標(biāo) -->
以上這篇詳談Android動(dòng)畫效果translate、scale、alpha、rotate就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
ImageView簡單加載網(wǎng)絡(luò)圖片實(shí)例代碼
使用ImageView實(shí)現(xiàn)簡單加載網(wǎng)絡(luò)圖片的功能,示例代碼如下,感興趣的朋友可以參考下哈,希望對(duì)大家有所幫助2013-06-06Android Studio 3.0被調(diào)方法參數(shù)名提示的取消方法
這篇文章主要介紹了去掉android studio 3.0被調(diào)方法參數(shù)名提示的解決方法,在文章末尾給大家補(bǔ)充介紹了Android Studio 3.0 gradle提示太老的解決方法,非常不錯(cuò),需要的朋友可以參考下2017-11-11Android7.0開發(fā)實(shí)現(xiàn)Launcher3去掉應(yīng)用抽屜的方法詳解
這篇文章主要介紹了Android7.0開發(fā)實(shí)現(xiàn)Launcher3去掉應(yīng)用抽屜的方法,結(jié)合實(shí)例形式分析了Android7.0 Launcher3調(diào)整界面布局的相關(guān)操作技巧與注意事項(xiàng),需要的朋友可以參考下2017-11-11Android 創(chuàng)建/驗(yàn)證/刪除桌面快捷方式(已測(cè)試可用)
桌面快捷方式的出現(xiàn)方便了用戶操作,在某些程度上提高了用戶體驗(yàn),接下來將介紹下Android創(chuàng)建/驗(yàn)證/刪除桌面快捷方式的實(shí)現(xiàn)思路及代碼,感興趣的朋友可以了解下,或許本文可以幫助到你2013-02-02Android ListView獲得選項(xiàng)中的值
本篇文章主要介紹Android ListView,在Android開發(fā)過程中經(jīng)常會(huì)用到ListView 組件并有監(jiān)聽事件,這里給大家一個(gè)簡單實(shí)例,來說明如何得到ListView選項(xiàng)中的值2016-07-07Android筆記之:App應(yīng)用之發(fā)布各廣告平臺(tái)版本的詳解
Android的廣告平臺(tái)是很多的,各市場(chǎng)對(duì)各平臺(tái)的接受程度是不一樣的,Android的開發(fā)者如果想集成廣告基本要考慮下面兩個(gè)問題2013-04-04