Android Animation学习(六) View Animation介绍
?
Android Animation學習(六) View Animation介紹
?
View Animation
View animation系統可以用來執行View上的Tween animation和Frame animation。
Tween animation可以在View對象上執行一系列的簡單變換,比如位置、尺寸、旋轉、透明度等。
animation package?包中包含了tween animation所有的類。
一系列的動畫命令定義了一個完整的tween animation,可以用代碼定義也可以用XML資源文件定義。
?
XML資源文件
XML資源文件的使用可以見:Animation Resources。
XML文件放在項目的res/anim/目錄下。文件必須有一個唯一的根節點。
這個根節點可以是:<alpha>, <scale>, <translate>, <rotate>, interpolator element, 或者是<set>。
默認情況下,所有的動畫都是并行進行的,要想使得它們順尋發生,你必須指定startOffset屬性。
?
有一些值,可以指定是相對于View本身還是相對于父類容器的。
比如pivotX,要表示相對于自身的50%,要用50%;要表示相對于父類容器的50%,則直接寫50。
?
使用例子
XML文件存儲為:res/anim/hyperspace_jump.xml:
<set xmlns:android="http://schemas.android.com/apk/res/android"android:shareInterpolator="false"><scaleandroid:interpolator="@android:anim/accelerate_decelerate_interpolator"android:fromXScale="1.0"android:toXScale="1.4"android:fromYScale="1.0"android:toYScale="0.6"android:pivotX="50%"android:pivotY="50%"android:fillAfter="false"android:duration="700" /><setandroid:interpolator="@android:anim/accelerate_interpolator"android:startOffset="700"><scaleandroid:fromXScale="1.4"android:toXScale="0.0"android:fromYScale="0.6"android:toYScale="0.0"android:pivotX="50%"android:pivotY="50%"android:duration="400" /><rotateandroid:fromDegrees="0"android:toDegrees="-45"android:toYScale="0.0"android:pivotX="50%"android:pivotY="50%"android:duration="400" /></set> </set>?
在代碼中把這個動畫應用于一個ImageView:
ImageView image = (ImageView) findViewById(R.id.image); Animation hyperspaceJump = AnimationUtils.loadAnimation(this, R.anim.hyperspace_jump); image.startAnimation(hyperspaceJump); ?除了調用?startAnimation() ,另一種處理方式是通過Animation.setStartTime()方法定義一個開始時間,然后通過View.setAnimation()方法把這個動畫賦給控件即可。
?
View Animation和Property Animation
View Animation是API Level 1就引入的。
View Animation在包android.view.animation中。
動畫類叫Animation。
?
Property Animation是API Level 11引入的,即Android 3.0才開始有Property Animation相關的API。
Property Animation API在包?android.animation中。
動畫相關類叫Animator。
?
參考資料
API Guides:View Animation
http://developer.android.com/guide/topics/graphics/view-animation.html
Tween animation的包:
http://developer.android.com/reference/android/view/animation/package-summary.html
Animation類:
http://developer.android.com/reference/android/view/animation/Animation.html
Animation Resources
http://developer.android.com/guide/topics/resources/animation-resource.html
?
轉載于:https://www.cnblogs.com/mengdd/p/3309731.html
總結
以上是生活随笔為你收集整理的Android Animation学习(六) View Animation介绍的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 面试常备题----数组总结篇(上)
- 下一篇: 数据下载工作笔记三:脚本