android动画之Interpolator和AnimationSet
来源:互联网 发布:知金教育待遇 编辑:程序博客网 时间:2024/06/05 21:02
如果在android中开发复合动画需要使用类AnimationSet 类 利用它的add 方法就可一加入动画 或者使用布局文件 set 加入多个动画就行 不过他们是在同一时间内开始动画的
1 xml代码 2 <?xml version="1.0"encoding="utf-8"?> 3 <setxmlns:android="http: android=""res=""apk=""schemas.android.com=""> 4 <translate 5 android:toXDelta="100%p" 6 android:fromXDelta="0" 7 android:duration="1000"> 8 </alpha> 9 </translate>10 </setxmlns:android="http:>
1 // 通过AnimationSet应用多个动画 2 // AnimationSet提供了一个把多个动画组合成一个组合的机制,并可设置组中动画的时序关系,如同时播放,顺序播放等。 3 // 以下例子同时应用5个动画: 4 // 播放anim1; 5 // 同时播放anim2,anim3,anim4; 6 // 播放anim5。 7 AnimatorSet bouncer = new AnimatorSet(); 8 bouncer.play(anim1).before(anim2); 9 bouncer.play(anim2).with(anim3);10 bouncer.play(anim2).with(anim4)11 bouncer.play(anim5).after(amin2);12 animatorSet.start();
AnimationSet可以加入Animation,加入之后设置AnimationSet对加入的所有Animation都有效。
1 AnimationSet anim=new AnimationSet(true); 2 AlphaAnimation a=new AlphaAnimation(1,0); 3 RotateAnimation ra=new RotateAnimation(0, 720, Animation.RELATIVE_TO_SELF,0.5f, Animation.RELATIVE_TO_SELF,0.5f); 4 anim.addAnimation(a); 5 anim.addAnimation(ra); 6 anim.setDuration(3000); 7 anim.setStartOffset(1000); 8 iv.startAnimation(anim); 9 10 AnimationSet anim=new AnimationSet(true);11 AlphaAnimation a=new AlphaAnimation(1,0);12 RotateAnimation ra=new RotateAnimation(0, 720, Animation.RELATIVE_TO_SELF,0.5f, Animation.RELATIVE_TO_SELF,0.5f);13 anim.addAnimation(a);14 anim.addAnimation(ra);15 anim.setDuration(3000);16 anim.setStartOffset(1000);17 iv.startAnimation(anim);
可以再xml文件中定义多个Animation,这样多个Animation可以一起运行
1 <?xml version="1.0" encoding="utf-8"?> 2 <set xmlns:android="http://schemas.android.com/apk/res/android" 3 android:interpolator="@android:anim/accelerate_interpolator" 4 android:shareInterpolator="true" 5 > 6 <alpha 7 android:fromAlpha="1.0" 8 android:toAlpha="0.0" 9 android:startOffset="500" 10 android:duration="3000" 11 /> 12 <rotate 13 android:fromDegrees="0" 14 android:toDegrees="400" 15 android:pivotX="50%" 16 android:pivotY="50%" 17 android:duration="3000" 18 /> 19 20 </set>
1 <?xml version="1.0" encoding="utf-8"?> 2 <set xmlns:android="http://schemas.android.com/apk/res/android" 3 android:interpolator="@android:anim/accelerate_interpolator" 4 android:shareInterpolator="true" 5 > 6 <alpha 7 android:fromAlpha="1.0" 8 android:toAlpha="0.0" 9 android:startOffset="500"10 android:duration="3000"11 />12 <rotate13 android:fromDegrees="0"14 android:toDegrees="400"15 android:pivotX="50%"16 android:pivotY="50%"17 android:duration="3000"18 />19 20 </set>
Interpolator可以定义动画播放的速度
在xml文件中定义Interpolator
android:interpolator="@android:anim/accelerate_interpolator"android:shareInterpolator="true"
这样所有的Animation共用一个Interpolator。
在代码中用代码设置如下
anim.setInterpolator(new AccelerateInterpolator());
在new一个AnimationSet中传入true则所有的Animation共用Interpolator
0 0
- Android动画之Interpolator和AnimationSet(三)
- Android动画之Interpolator和AnimationSet
- Android动画之Interpolator和AnimationSet(三)
- Android动画之Interpolator和AnimationSet(三)
- Android动画之Interpolator和AnimationSet(三)
- Android动画之Interpolator和AnimationSet(三)
- android动画之Interpolator和AnimationSet
- Android动画之Interpolator和AnimationSet
- Android动画之Interpolator和AnimationSet
- Android动画之Interpolator和AnimationSet(三)
- android:interpolator animationSet属性
- android 动画AnimationSet 和 AnimatorSet
- android 动画AnimationSet 和 AnimatorSet
- android动画之Interpolator
- Android 动画之interpolator
- Android动画之Interpolator插补器
- Android动画之Interpolator插补器
- android动画 之Interpolator类
- Android UI开发——使用Fragment构建灵活的桌面
- Longest Consecutive Sequence
- tools:context=".MainActivity的作用
- android ImageView scaleType属性
- Android中Animation详解
- android动画之Interpolator和AnimationSet
- Android getWindow().setFlags方法
- android 布局中 layout_gravity、gravity、orientation、layout_weight
- activity之间跳转动画失效原因
- List,set,Map 的用法和区别
- Dialog样式
- ListView设背景
- Style与Theme
- EditText属性