溫馨提示×

溫馨提示×

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

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

Android——Animation

發(fā)布時間:2020-06-12 22:06:21 來源:網絡 閱讀:251 作者:wauoen 欄目:移動開發(fā)

Android中的動畫:

一、分類:TweenAnimation(補間動畫)和FrameAnimation(幀動畫)。

  1. TweenAnimation,通過對圖像不斷做變換產生動畫效果,是一種漸變效果;

    AlphaAnimation:透明度漸變;

    ScaleAnimation:尺寸縮放;

    TranslateAnimation:移動

    RotateAnimation:旋轉

  2. FrameAnimation:順序播放事先做好的圖像是一種轉換動畫;

二、屬性簡介:

  1. TweenAnimation共同屬性:

android:duration [long] :動畫持續(xù)的時間;

android:fillAfter [boolean]:視圖停在動畫結束的位置,但是真正的位置仍然是布局中給定位置;

android:fillBefore[boolean]:視圖停在動畫開始的位置;

android:interpolator :指定一個動畫的插入器,常用的插入器有:

    accelerater_decelerate_interpolator:加速-減速 動畫插入器

    accelerater_interpolator:加速動畫插入器;

    deceleratr_interpolator:減速動畫插入器;

android:repeatCount[int]:動畫重復次數,-1表示無限循環(huán);

android:repeatMode[int]:定義動畫重復的行為,1,從起點重新開始;2,從結束位置開始相反執(zhí)行;

android:startOffset[long]:動畫之間的時間間隔,從上次動畫停多少時間開始執(zhí)行下個動畫;

android:zAdjustment[int]:定義動畫的Z order的改變,0:保持Z Order不變;1:保持在最上層;-1保持在最下層;(????待驗證)

1.1 AlphaAnimation

xml中定義

<!-- 	<alpha android:fromAlpha="" 開始時的透明度,0.0-1.0 -->
<!-- 	    android:toAlpha="" 結束時的透明度 0.0-1.0 -->
<!-- 	    android:duration="" 動畫持續(xù)的時間 /> -->

代碼中定義:

//fromAlpha:開始時的透明度,toAlpha:結束時的透明度
		AlphaAnimation alpha = new AlphaAnimation(fromAlpha, toAlpha);
		//設置動畫持續(xù)的時間
		alpha.setDuration(durationMillis);

1.2 ScaleAnimation

xml

<!-- <scale  -->
<!--     android:fromXScale="" 動畫起始時X坐標上的伸縮尺寸-->
<!--     android:toXScale="" 動畫結束時X坐標上的伸縮尺寸-->
<!--     android:fromYScale="" 動畫起始時Y軸上的伸縮尺寸-->
<!--     android:toYScale="" 動畫結束時Y軸上的伸縮尺寸-->
<!--     android:pivotX="" 動畫相對于物件的X坐標的開始位置-->
<!--     android:pivotY="" 動畫相對與物件Y坐標的開始位置-->
<!--     /> -->

代碼中

ScaleAnimation scale = new ScaleAnimation(fromX, toX, fromY, toY);

1.3 TranslateAnimation

xml

    <translate
        android:fromXDelta="0%" //x軸起始位置
        android:pivotX="0%" //動畫相對于物件X坐標的開始位置
        android:pivotY="0%"http://動畫相對于物件Y坐標的開始位置
        android:toXDelta="30%" //x軸的結束位置
        android:fromYDelta="0%" //y軸起始位置
        android:toYDelta="0%" //y軸結束位置
        android:duration="10000"/>

代碼中:

TranslateAnimation anim = new TranslateAnimation(fromXDelta, toXDelta, fromYDelta, toYDelta)

1.4 RotateAnimation

xml

    <!-- <rotate -->
    <!-- android:fromDegrees="" 動畫起始時物件的角度 -->
    <!-- android:toDegrees="" 動畫結束時物件旋轉的角度 -->
    <!-- 角度為負表示逆時針旋轉,角度為正表示順時針旋轉 -->
    <!-- android:pivotX="" 動畫相對于物件X坐標的開始位置 -->
    <!-- android:pivotY="" 動畫相對與物件Y坐標的開始位置 -->
    <!-- android:duration="" 動畫運行時間/> -->

代碼:

		ScaleAnimation anim = new ScaleAnimation(fromX, toX, fromY, toY)

2.xml定義動畫在activity中的使用:

Animation animation = (Animation) AnimationUtils.loadAnimation(MainActivity.this, R.anim.animation);

3.插值器的使用

Interpolator對象資源ID功能作用
AccelerateDecelerateInterpolator@android:anim/accelerate_decelerate_interpolator先加速再減速
AccelerateInterpolator@android:anim/accelerate_interpolator加速
AnticipateInterpolator@android:anim/anticipate_interpolator先回退一小步然后加速前進
AnticipateOvershootInterpolator@android:anim/anticipate_overshoot_interpolator在上一個基礎上超出終點一小步再回到終點
BounceInterpolator@android:anim/bounce_interpolator最后階段彈球效果
CycleInterpolator@android:anim/cycle_interpolator周期運動
DecelerateInterpolator@android:anim/decelerate_interpolator減速
LinearInterpolator@android:anim/linear_interpolator勻速
OvershootInterpolator@android:anim/overshoot_interpolator快速到達終點并超出一小步最后回到終點

4.FrameAnimation:幀動畫

添加圖片,按照添加圖片的順序播放;

		AnimationDrawable anima = new AnimationDrawable();
		anima.addFrame(drawable1, duration1);
		anima.addFrame(drawable2, duration2);
		anima.addFrame(drawable3, duration3);
		anima.addFrame(drawable4, duration4);
		view.setBackgroudDrawable(anima);


向AI問一下細節(jié)

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

AI