现在的位置: 首页 > 综合 > 正文

Android动画功能

2018年05月09日 ⁄ 综合 ⁄ 共 1728字 ⁄ 字号 评论关闭

Android动画功能

调用一个视图的startAnimation方法,视图就会有动画效果了

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

view.startAnimation(translate);

一、Translate 定義視圖平移距離

定義視圖從Y軸的底部移到頂部,動畫完成時間為3秒

<set xmlns:android="http://schemas.android.com/apk/res/android">

   <translate

       android:fromYDelta="480"

       android:toYDelta="0"

       android:duration="3000"/>

</set>

定義視圖從X軸的左邊移到右邊,動畫完成時間為3秒

<set xmlns:android="http://schemas.android.com/apk/res/android">

   <translate

       android:fromXDelta="0"

       android:toXDelta="320"

       android:duration="3000"/>

</set>

注:Delta也可以用%p為單位 

例子:

android:fromXDelta="0" android:toXDelta="-100%p" 往左邊消失

android:fromXDelta="-100%p" android:toXDelta="0" 從左邊進

android:fromXDelta="0" android:toXDelta="100%p" 往右邊消失

android:fromXDelta="100%p" android:toXDelta="0" 從右邊進

二、Rotate 定義視圖旋轉角度

視圖的中心位置旋轉360度,時間1秒完成

<set xmlns:android="http://schemas.android.com/apk/res/android">

<rotate 

    android:fromDegrees="0"

    android:toDegrees="+360"

    android:pivotX="50%"

    android:pivotY="50%"

    android:duration="1000"/>

</set>

三、Scale 定義視圖縮放動畫

<set xmlns:android="http://schemas.android.com/apk/res/android"  

        android:interpolator="@android:anim/accelerate_interpolator">  

   <scale android:fromXScale="0.0" android:toXScale="1.0"  

         android:fromYScale="0.0" android:toYScale="1.0"  

         android:pivotX="50%p" android:pivotY="50%p"  

         android:duration="300"/>  

</set> 
//上面的效果為從中間爆出來的效果,可用于Activity的過度效果

釋:Scale定義如何沿著x軸方向(或y軸方向)改變視圖的大小,視圖大小發生變化時樞軸(pivot)位置是保持不變的 pivotX/pivotY為x/y軸的百分比

四、Alpha 定義視圖的透明痛

<set xmlns:android="http://schemas.android.com/apk/res/android">

<alpha 

    android:fromAlpha="0.1"

    android:toAlpha="1.0"

    android:duration="3000"/>

</set>

    注:透明度變化范圍從0.0(透明)到1.0(不透明)

抱歉!评论已关闭.