溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Android中的補(bǔ)間動畫(tween)的簡單使用

發(fā)布時(shí)間:2020-07-10 16:38:46 來源:網(wǎng)絡(luò) 閱讀:439 作者:ccdebug 欄目:移動開發(fā)

相對幀動畫,補(bǔ)間動畫(tween)可以這么理解:我們不必像幀動畫一樣指定動畫的每一幀,只需定義一個(gè)動畫的開始和結(jié)束關(guān)鍵幀,而中間變化的幀由系統(tǒng)幫我們計(jì)算。

tween動畫可以分為下面幾種:

AlphaAnimation(透明漸變動畫):

示例:res/anim/alpha.xml

<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="2000"  
    android:fillAfter="true"
    android:fromAlpha="0.0"
    android:repeatCount="1"
    android:repeatMode="reverse"
    android:toAlpha="1.0" >

</alpha>

屬性介紹:

duration:動畫持續(xù)的時(shí)間

fromAlpha:漸變開始值,F(xiàn)loat 0.0完全透明 1.0完全不透明

toAlpha:漸變結(jié)束值

repeatCount: 動畫重復(fù)次數(shù)

repeatMode:動畫重復(fù)模式,["repeat"|"reverse"] repeat(透明-不透明 透明-不透明)

reverse(透明-不透明 不透明-透明)

開始動畫:

Animation animation = AnimationUtils.loadAnimation(this, R.anim.alpha);
iv.startAnimation(animation);    //使用ImageView的startAnimation開始動畫

ScaleAnimation(縮放動畫):

res/anim/scale.xml

<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="2000"
    android:fillAfter="false"
    android:fromXScale="0.2"
    android:fromYScale="0.2"
    android:pivotX="50%"
    android:pivotY="50%"
    android:repeatCount="1"
    android:repeatMode="reverse"
    android:toXScale="2.0"
    android:toYScale="2.0" >

</scale>

主要屬性說明:

fromXScale,fromYScale: 動畫開始時(shí)縮放比(x,y軸)

toXScale,toYscale: 動畫結(jié)束時(shí)縮放比

pivotX,pivotY:縮放中心點(diǎn) (50%,50%)則為自身中心點(diǎn)(0,0)左上方


TranslateAnimation(位移動畫):

res/anim/translate.xml

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromXDelta="-50%p"
    android:fromYDelta="0.0"
    android:toXDelta="50%p"
    android:toYDelta="0.0"
    android:repeatCount="1"
    android:repeatMode="reverse"
    android:duration="2000"
     >

</translate>

fromXDelta fromYDelta:開始位置坐標(biāo),可以是Float值和百分比 50%p以父容器為參考

toXDelta toYDelta: 結(jié)束位置坐標(biāo)

RotateAnimation(旋轉(zhuǎn)動畫):

res/anim/rotate.xml

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="0"
    android:toDegrees="360"
    android:pivotX="50%"
    android:pivotY="50%"
    android:repeatCount="1"
    android:repeatMode="reverse"
    android:duration="2000" >

</rotate>

屬性介紹:

fromDegrees:旋轉(zhuǎn)開始角度

toDegrees:旋轉(zhuǎn)結(jié)束角度,

pivotX pivotY:旋轉(zhuǎn)中心點(diǎn)

上面動畫實(shí)現(xiàn)以自身中心點(diǎn)為基準(zhǔn)點(diǎn)旋轉(zhuǎn)360度

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI