日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

安卓动画知识总结 Animation AnimationSet LayoutAnimation

發布時間:2023/12/15 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 安卓动画知识总结 Animation AnimationSet LayoutAnimation 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
本文由PurpleSword(jzj1993)原創,轉載請注明 原文網址 http://blog.csdn.net/jzj1993
常見動畫有幾種
控件View的動畫(如Dialog窗口中的圓形進度條) 空間Window的動畫(如DialogWindow,PopupWindow的動畫,Activity切換時整個Window頁面的動畫) ViewGroup的LayoutAnimation動畫,每個子控件按照設定的順序、延遲播放動畫
動畫常用anim/*.xml定義
xml中定義動畫,可直接使用<translate><scale><alpha><rotate>標簽直接定義,也可以放在<set>標簽中,里面定義的動畫將同時開始播放。 兩者都可使用AnimationUtils.loadAnimation方法加載。如果是set標簽定義,加載時返回的是AnimationSet實例(AnimationSet繼承自Animation) 在set標簽中設置的一些屬性,會直接覆蓋它里面定義動畫的對應屬性,而?AnimationSet的另外一些從Animation繼承的屬性則無效,下面是AnimationSet類的官方說明。
Represents a group of Animations that should be played together. The transformation of each individual animation are composed together into a single transform. If AnimationSet sets any properties that its children also set (for example, duration or fillBefore), the values of AnimationSet override the child values.

The way that AnimationSet inherits behavior from Animation is important to understand. Some of the Animation attributes applied to AnimationSet affect the AnimationSet itself, some are pushed down to the children, and some are ignored, as follows:

    • duration, repeatMode, fillBefore, fillAfter: These properties, when set on an AnimationSet object, will be pushed down to all child animations.
    • repeatCount, fillEnabled: These properties are ignored for AnimationSet.
    • startOffset, shareInterpolator: These properties apply to the AnimationSet itself.
Starting with?android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH, the behavior of these properties is the same in XML resources and at runtime (prior to that release, the values set in XML were ignored for AnimationSet). That is, calling?setDuration(500)?on an AnimationSet has the same effect as declaring?android:duration="500"?in an XML resource for an AnimationSet object.

常規補間動畫:彈跳(移動)
Layout/activity_welcome_anim.xml (0%p表示占父組件尺寸的百分比)
<?xml?version="1.0"?encoding="utf-8"?> <set?xmlns:android="http://schemas.android.com/apk/res/android"?> ????<translate ????????android:duration="500" ????????android:fromXDelta="0" ????????android:fromYDelta="0%p" ????????android:interpolator="@android:anim/accelerate_interpolator" ????????android:toXDelta="0" ????????android:toYDelta="42%p"?/> ????<translate ????????android:duration="350" ????????android:fromXDelta="0" ????????android:fromYDelta="0" ????????android:interpolator="@android:anim/decelerate_interpolator" ????????android:startOffset="500" ????????android:toXDelta="0" ????????android:toYDelta="-21%p"?/> ????<translate ????????android:duration="350" ????????android:fromXDelta="0" ????????android:fromYDelta="0" ????????android:interpolator="@android:anim/accelerate_interpolator" ????????android:startOffset="850" ????????android:toXDelta="0" ????????android:toYDelta="21%p"?/> ????<translate ????????android:duration="250" ????????android:fromXDelta="0" ????????android:fromYDelta="0" ????????android:interpolator="@android:anim/decelerate_interpolator" ????????android:startOffset="1200" ????????android:toXDelta="0" ????????android:toYDelta="-10%p"?/> ????<translate ????????android:duration="250" ????????android:fromXDelta="0" ????????android:fromYDelta="0" ????????android:interpolator="@android:anim/accelerate_interpolator" ????????android:startOffset="1450" ????????android:toXDelta="0" ????????android:toYDelta="10%p"?/> ????<translate ????????android:duration="150" ????????android:fromXDelta="0" ????????android:fromYDelta="0" ????????android:interpolator="@android:anim/decelerate_interpolator" ????????android:startOffset="1700" ????????android:toXDelta="0" ????????android:toYDelta="-5%p"?/> ????<translate ????????android:duration="150" ????????android:fromXDelta="0" ????????android:fromYDelta="0" ????????android:interpolator="@android:anim/accelerate_interpolator" ????????android:startOffset="1850" ????????android:toXDelta="0" ????????android:toYDelta="5%p"?/> </set>
再例如常規補間動畫:縮放、透明度
<?xml?version="1.0"?encoding="utf-8"?> <set?xmlns:android="http://schemas.android.com/apk/res/android"?> ????<scale ????????android:duration="800" ????????android:fromXScale="0.0" ????????android:fromYScale="0.0" ????????android:pivotX="50%" ????????android:pivotY="50%" ????????android:toXScale="1.0" ????????android:toYScale="1.0"?/> ????<alpha ????????android:duration="800" ????????android:fromAlpha="0.0" ????????android:toAlpha="1.0"?/> </set>
再如上浮效果(移動、透明度)
<?xml?version="1.0"?encoding="utf-8"?> <set?xmlns:android="http://schemas.android.com/apk/res/android" ????android:interpolator="@android:anim/linear_interpolator"?> ????<translate ????????android:duration="500" ????????android:fromXDelta="0" ????????android:fromYDelta="5%" ????????android:toXDelta="0" ????????android:toYDelta="0%"?/> ????<alpha ????????android:duration="500" ????????android:fromAlpha="0.0" ????????android:toAlpha="1.0"?/> ????<alpha ????????android:duration="100" ????????android:fromAlpha="1.0" ????????android:startOffset="1400" ????????android:toAlpha="1.0"?/> </set>
可使用Java程序加載

? ??this.setContentView(R.layout.activity_welcome);
? ??anim?=?AnimationUtils.loadAnimation(this, ? ? ? ? ? ? R.anim.welcome_anim); ? ??//?動畫效果執行完畢后,View對象保留在終止的位置?
? ??anim.setFillEnabled(true);
? ??anim.setFillAfter(true);

? ? this.findViewById(R.id.point).setAnimation(anim);


還可設置動畫監聽器

? ??anim.setAnimationListener(listener);

? ??/**
? ? ?*?動畫監聽器
? ? ?*/
? ??private?AnimationListener?listener?=?new?AnimationListener()?{
? ? ? ??@Override
? ? ? ??public?void?onAnimationEnd(Animation?animation)?{
? ? ? ? ? ? // startMain();
? ? ? ? }
? ? ? ??@Override
? ? ? ??public?void?onAnimationStart(Animation?animation)?{
? ? ? ? }
? ? ? ??@Override
? ? ? ??public?void?onAnimationRepeat(Animation?animation)?{
? ? ? ? }
????};
在Dialog中動畫的加載
? ? ? ? LayoutInflater?inflater?=?LayoutInflater.from(context); ????????View?v?=?inflater.inflate(R.layout.dialog_voice,?null); ????????ImageView?img?=?(ImageView)?v.findViewById(R.id.dialog_img); ????????Animation?anim?=?AnimationUtils.loadAnimation(context, ????????????????R.anim.center_rotate_repeat); ????????img.startAnimation(anim); ????????new?AlertDialog.Builder(context).setView(v);
給整個Dialog設置動畫 ? ??dialog.getWindow().setWindowAnimations(R.style.quick_scale_anim);
給PopupWindow設置動畫 ? ??pop.setAnimationStyle(R.style.quick_scale_anim);


Activity的切換動畫
? ??代碼實現Activity切換動畫
? ? startActivity(new?Intent(this,?ListAlarm.class)); ? ? overridePendingTransition(R.anim.anim_activity_in, ????????????????R.anim.anim_activity_unchange);
? ??或者 ? ? ActivityGuide.this.finish(); ? ? overridePendingTransition(R.anim.alpha_stay,?R.anim.alpha_exit);
? ? 在XML中定義Activity切換動畫
Activity切換動畫:不能設置SingleInstance屬性,會導致動畫失效
? ??<style?name="activityAnimation"?parent="@android:style/Animation"> ????????<item?name="android:windowEnterAnimation">@null</item> ????????<item?name="android:windowExitAnimation">@null</item> ????????<!--?新的Activity啟動時Enter動畫?--> ????????<item?name="android:activityOpenEnterAnimation">@anim/slide_left_in</item> ????????<!--?新的Activity啟動時原有Activity的Exit動畫?--> ????????<item?name="android:activityOpenExitAnimation">@anim/keep</item> ????????<!--?新的Activity退出時原有ActivityEnter動畫?--> ????????<item?name="android:activityCloseEnterAnimation">@anim/keep</item> ????????<!--?新的Activity退出時Exit動畫?--> ????????<item?name="android:activityCloseExitAnimation">@anim/slide_right_out</item> ????</style>

? ??Manifest.xml ? ??<application ????????android:theme="@style/app_theme"?> ? ? ? ??<activity ????????????android:name=".ui.ActivityWelcome" ????????????android:theme="@style/app_theme_fullscreen"?> ????????</activity> ????</application>
? ??style.xml ? ??<style?name="app_theme"?parent="@android:style/Theme.Light.NoTitleBar"> ????????<item?name="android:windowAnimationStyle">@style/activity_anim</item> ????</style>
????<style?name="activity_anim"> ????????<item?name="android:windowEnterAnimation">@anim/quick_alpha_enter</item> ????????<item?name="android:windowExitAnimation">@anim/quick_alpha_stay</item> ????</style>
? ??anim/quick_alpha_enter.xml
? ??anim/quick_alpha_stay.xml

LayoutAnimation
1、在 layout_anim_item.xml 中定義子View動畫

2、在 layout_anim.xml 中定義Layout動畫,并引用子View動畫
<layoutAnimation?xmlns:android="http://schemas.android.com/apk/res/android" ????android:animation="@anim/layout_anim_item" ????android:animationOrder="normal" ????android:delay="0.25"?/>

3、在ViewGroup中引用自定義Layout動畫 <ViewGroup ????android:layoutAnimation="@anim/layout_anim"?>
近期自己搭建了一個網站,以后我的博客會轉移到個人網站,歡迎大家關注~ 網址是http://purplesword.info



總結

以上是生活随笔為你收集整理的安卓动画知识总结 Animation AnimationSet LayoutAnimation的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。