安卓 动画小结
2019獨角獸企業重金招聘Python工程師標準>>>
補間動畫(Tween Animation)
a. 漸變動畫支持四種類型:平移(Translate)、旋轉(Rotate)、縮放(Scale)、不透明度(Alpha)。
b. 只是顯示的位置變動,View的實際位置未改變,表現為View移動到其他地方,點擊事件仍在原處才能響應。
c. 組合使用步驟較復雜。
d. View Animation 也是指此動畫。
幀動畫(Frame?Animation)
a. 用于生成連續的Gif效果圖。
b. DrawableAnimation也是指此動畫。
屬性動畫(Property?Animation)
a. 支持對所有View能更新的屬性的動畫(需要屬性的setXxx()和getXxx())。
b. 更改的是View實際的屬性,所以不會影響其在動畫執行后所在位置的正常使用。
逐幀動畫 frame_anim.xml
<?xml?version="1.0"?encoding="utf-8"?> <animation-list?xmlns:android="http://schemas.android.com/apk/res/android"android:oneshot="false"?><!--?android:oneshot="false"?表示不循環播放?--><itemandroid:drawable="@drawable/ni"android:duration="500"/><itemandroid:drawable="@drawable/hao"android:duration="500"/><itemandroid:drawable="@drawable/huan"android:duration="500"/><itemandroid:drawable="@drawable/yin"android:duration="500"/><itemandroid:drawable="@drawable/lai"android:duration="500"/><itemandroid:drawable="@drawable/dao"android:duration="500"/><itemandroid:drawable="@drawable/wo"android:duration="500"/><itemandroid:drawable="@drawable/de"android:duration="500"/><itemandroid:drawable="@drawable/bo"android:duration="500"/><itemandroid:drawable="@drawable/ke"android:duration="500"/></animation-list>java中代碼
//anim的backgroud="@anim/frame_anim" final?ImageView?anim?=?(ImageView)?findViewById(R.id.anim); final?AnimationDrawable?animation?=?(AnimationDrawable)?anim.getBackground();animation.start(); animation.stop();http://download.csdn.net/download/qq_26972449/9373567參考例子
補間動畫 透明
<alpha???xmlns:android="http://schemas.android.com/apk/res/android"???android:fromAlpha="0.1"?????android:toAlpha="1.0"?????android:duration="1000"??/> fromAlpha?屬性為動畫起始時透明度 toAlpha???屬性為動畫結束時透明度?????? 0.0??表示完全透明 1.0??表示完全不透明 duration??屬性為動畫持續時間??時間以毫秒為單位java代碼
旋轉
<rotate??????android:interpolator="@android:anim/accelerate_decelerate_interpolator"?????android:fromDegrees="0"?????android:toDegrees="+350"?????????????android:pivotX="50%"?????android:pivotY="50%"?????????android:duration="3000"?/>???<!--?rotate?旋轉動畫效果屬性: interpolator?指定一個動畫的插入器??? accelerate_decelerate_interpolator???加速-減速動畫插入器 accelerate_interpolator??????????????加速-動畫插入器 decelerate_interpolator??????????????減速-動畫插入器 fromDegrees?屬性為動畫起始時物件的角度 toDegrees???屬性為動畫結束時物件旋轉的角度 可以大于360度 說明:?????? 當角度為負數——表示逆時針旋轉 當角度為正數——表示順時針旋轉 (負數from——to正數:順時針旋轉)??????? (負數from——to負數:逆時針旋轉)????? (正數from——to正數:順時針旋轉)?????? (正數from——to負數:逆時針旋轉)??????????? pivotX?????屬性為動畫相對于物件的X坐標的開始位置 pivotY?????屬性為動畫相對于物件的Y坐標的開始位置 說明:????????以上兩個屬性值從0%-100%中取值50%為物件的X或Y方向坐標上的中點位置 長整型值:duration??屬性為動畫持續時間?時間以毫秒為單位-->java代碼
AnimationrotateAnimation=new?RotateAnimation(0,?45); rotateAnimation.setDuration(3000);//設置動畫持續時間為3秒 rotateAnimation.setFillAfter(true);//設置動畫結束后保持當前的位置(即不返回到動畫開始前的位置) imgShow.startAnimation(rotateAnimation); myAnimation_Rotate=new?RotateAnimation(0.0f,?+350.0f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,?0.5f);縮放
<?xml?version="1.0"?encoding="utf-8"?>?????? <set?xmlns:android="http://schemas.android.com/apk/res/android"android:fillAfter="true"> <!--?尺寸伸縮動畫效果scale?????? 屬性:interpolator?指定一個動畫的插入器?? accelerate_decelerate_interpolator??加速-減速?動畫插入器 accelerate_interpolator????????加速-?動畫插入器 decelerate_interpolator????????減速-?動畫插入器 其他的屬于特定的動畫效果 浮點型值:fromXScale?屬性為動畫起始時X坐標上的伸縮尺寸 toXScale???屬性為動畫結束時X坐標上的伸縮尺寸 fromYScale?屬性為動畫起始時Y坐標上的伸縮尺寸 toYScale???屬性為動畫結束時Y坐標上的伸縮尺寸 startOffset??屬性為從上次動畫停多少時間開始執行下個動畫 說明:??????以上四種屬性值 0.0表示收縮到沒有 1.0表示正常無伸縮 值小于1.0表示收縮 值大于1.0表示放大 pivotX?????屬性為動畫相對于物件的X坐標的開始位置 pivotY?????屬性為動畫相對于物件的Y坐標的開始位置 說明:?????? 以上兩個屬性值從0%-100%中取值50%為物件的X或Y方向坐標上的中點位置 長整型值:duration??屬性為動畫持續時間?時間以毫秒為單位 布爾型值:?fillAfter?屬性當設置為true?,該動畫轉化在動畫結束后被應用 --><scale??????? android:interpolator="@android:anim/accelerate_decelerate_interpolator"????? android:fromXScale="1"????? android:toXScale="1"????? android:fromYScale="0"????? android:toYScale="1"?????? android:pivotX="0"????? android:pivotY="1"?? android:startOffset="1"???? android:duration="700"?/>????? </set>java 代碼
Animationscale?Animation=new?ScaleAnimation(0.5f,?1.0f,1.0f,?1.0f); scaleAnimation.setDuration(2000);//設置動畫持續時間為3秒 scaleAnimation.setFillAfter(true);//設置動畫結束后保持當前的位置(即不返回到動畫開始前的位置) scaleAnimation.setRepeatCount(3); imgShow.startAnimation(scaleAnimation); myAnimation_Scale?=new?ScaleAnimation(0.0f,?1.4f,?0.0f,?1.4f,Animation.RELATIVE_TO_SELF,?0.5f,?Animation.RELATIVE_TO_SELF,?0.5f);移動
<?xml?version="1.0"?encoding="utf-8"?> <!--?translate? 整型值:?????? fromXDelta?屬性為動畫起始時X坐標上的位置 toXDelta???屬性為動畫結束時X坐標上的位置 fromYDelta?屬性為動畫起始時Y坐標上的位置 toYDelta???屬性為動畫結束時Y坐標上的位置 注意:?????? 沒有指定fromXType?toXType?from?YType?toYType?時候,默認是以自己為相對參照物長整型值: duration??屬性為動畫持續時間 說明:時間以毫秒為單位-->????? <translate???xmlns:android="http://schemas.android.com/apk/res/android"??android:fromXDelta="0"?????android:toXDelta="10"?????android:duration="1000"?android:interpolator="@anim/cycle_4" />Java 代碼
AnimationtranslateAnimation=new?TranslateAnimation(0,?100,?0,?0); translateAnimation.setDuration(3000);//設置動畫持續時間為3秒 translateAnimation.setInterpolator(this,?android.R.anim.cycle_interpolator);//設置動畫插入器 translateAnimation.setFillAfter(true);//設置動畫結束后保持當前的位置(即不返回到動畫開始前的位置) imgShow.startAnimation(translateAnimation);多個動畫組合
AnimationSet?animationSet?=?new?AnimationSet(true); AlphaAnimation?alphaAnimation?=?new?AlphaAnimation(1,?0); RotateAnimation?rotateAnimation?=?new?RotateAnimation(0,?360,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f); rotateAnimation.setDuration(1000); animationSet.addAnimation(rotateAnimation); animationSet.addAnimation(alphaAnimation); image.startAnimation(animationSet);屬性動畫
相關的類
ObjectAnimator ?動畫的執行類,后面詳細介紹
ValueAnimator 動畫的執行類,后面詳細介紹?
AnimatorSet 用于控制一組動畫的執行:線性,一起,每個動畫的先后執行等。
AnimatorInflater 用戶加載屬性動畫的xml文件
TypeEvaluator ?類型估值,主要用于設置動畫操作屬性的值。
總的來說,屬性動畫就是,動畫的執行類來設置動畫操作的對象的屬性、持續時間,開始和結束的屬性值,時間差值等,然后系統會根據設置的參數動態的變化對象的屬性。
ObjectAnimator//??.ofFloat(view,?"rotationX",?0.0F,?360.0F)//?x軸旋轉?.setDuration(500)//??.start();??//rotationY?Y軸旋轉//rotation??旋轉//translationX?X軸移動//translationY?Y軸移動//scaleX?X軸縮放//scaleY?Y軸縮放ObjectAnimator?animator1?=?ObjectAnimator.ofFloat(textView,?"scaleX",?0F,?1F,0F,2F);//alpha?透明度ObjectAnimator?animator1?=?ObjectAnimator.ofFloat(textView,?"alpha",?0F,?1F,0F);多個動畫
//同步動畫設計 PropertyValuesHolder?p1?=?PropertyValuesHolder.ofFloat("translationX",?0,?360F); PropertyValuesHolder?p2?=?PropertyValuesHolder.ofFloat("translationY",?0,?360F); PropertyValuesHolder?p3?=?PropertyValuesHolder.ofFloat("rotation",?0,?360F); ObjectAnimator.ofPropertyValuesHolder(imageView,?p1,?p2?,p3).setDuration(1000).start();//通過AnimatiorSet來設計同步執行的多個屬性動畫 ObjectAnimator?animator1?=?ObjectAnimator.ofFloat(imageView,?"translationX",?0F,?360F);//X軸平移旋轉 ObjectAnimator?animator2?=?ObjectAnimator.ofFloat(imageView,?"translationY",?0F,?360F);//Y軸平移旋轉 ObjectAnimator?animator3?=?ObjectAnimator.ofFloat(imageView,?"rotation",?0F,?360F);//360度旋轉 AnimatorSet?set?=?new?AnimatorSet(); set.playSequentially(animator1,?animator2,?animator3);//分步執行 set.playTogether(animator1,?animator2,?animator3);//同步執行//屬性動畫的執行順序控制 set.play(animator3).with(animator1);??//同步 set.play(animator2).after(animator3);?//異步set.setDuration(1000); set.start();屬性動畫更多高級用法
http://blog.csdn.net/guolin_blog/article/details/43536355
http://blog.csdn.net/guolin_blog/article/details/43816093
轉載于:https://my.oschina.net/u/274829/blog/625859
總結
- 上一篇: 跳转指令
- 下一篇: apple air装双系统(win7)