本文主要是介绍Android_动画:Interpolator,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
- 效果图
- 2种创建方式
- xml创建
- java创建
- 注意
- 使用path需要API21
- Demo
效果图
2种创建方式
Interpolator
有2种创建方式,一种用xml
创建,一种用java创建。
OvershootInterpolator overshoot = new OvershootInterpolator(1.0f);
OvershootInterpolator interpolator = (OvershootInterpolator) AnimationUtils.loadInterpolator(MainActivity.this, android.R.interpolator.overshoot);不强制转化,用Interpolator也可以
Interpolator interpolator =AnimationUtils.loadInterpolator(MainActivity.this, android.R.interpolator.overshoot);
注意:Interpolator
是包android.view.animation
下
import android.view.animation.Interpolator;
xml创建
private boolean flag = true;
Interpolator interpolator = AnimationUtils.loadInterpolator(MainActivity.this, android.R.interpolator.bounce);Path path1 = new Path();
path1.moveTo(1.0f, 1.0f);
path1.lineTo(0.2f, 0.2f);ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(view, View.SCALE_X, View.SCALE_Y, path);
objectAnimator.setDuration(2000);
objectAnimator.setInterpolator(interpolator);
objectAnimator.start();
TranslationX
、scaleX
都是常量
常量 | 值 |
---|---|
View.TRANSLATION_X | translationX |
View.TRANSLATION_Y | translationY |
View.TRANSLATION_Z | |
View.SCALE_X | translationZ |
View.SCALE_Y | scaleX |
View.ALPHA | scaleY |
View.ROTATION | alpha |
View.ROTATION_X | rotationX |
View.ROTATION_Y | rotationY |
xml的interpolator
有多种类型
java创建
BounceInterpolator interpolator2 = new BounceInterpolator();
ObjectAnimator objectAnimatorX = ObjectAnimator.ofFloat(view, View.SCALE_X, 0.2f, 1.0f);
ObjectAnimator objectAnimatorY = ObjectAnimator.ofFloat(view, View.SCALE_Y, 0.2f, 1.0f);AnimatorSet set = new AnimatorSet();
set.playTogether(objectAnimatorX,objectAnimatorY);
set.setInterpolator(interpolator2);
set.setDuration(2000);
set.start();
Interpolator
是interface
,它有很多实现的子类
AccelerateDecelerateInterpolator,
AccelerateInterpolator,
AnticipateInterpolator,
AnticipateOvershootInterpolator,
BaseInterpolator,
BounceInterpolator,
CycleInterpolator,
DecelerateInterpolator,
FastOutLinearInInterpolator,
FastOutSlowInInterpolator,
LinearInterpolator,
LinearOutSlowInInterpolator,
OvershootInterpolator,
PathInterpolator
注意
使用path需要API>=21
ObjectAnimator.ofFloat(view, View.SCALE_X, View.SCALE_Y, path);//API>=21
ObjectAnimator.ofFloat(view,View.SCALE_X,0.2f,1.0f);
Demo
http://git.oschina.net/AnimationDemo/interpolator01
这篇关于Android_动画:Interpolator的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!