定义动画一般是通过定义关键帧(首帧或是尾帧)然后由系统自动生成中间帧,生成中间帧的过程可以称为“插值 interpolate”。Android Animation 支持多种插值算法:Interpolators (可以翻译成插值器)。
所有Interpolators 都实现Interpolator 接口(实际上为TimeInterpolator接口),这个接口定义了一个方法:
public abstract float getInterpolation(float input)
- input 为正规化后动画的时间,值域总之0-1之间。 0代表开始时间,1代表结束时间。
- 返回值也是正规化后的值,可以代表平移的时间,旋转的角度,Alpha值变化,标准值域为0-1之间,但允许值小于0或大于1,表示插值到标准区域两边。
总的来说,Interpolator定义了动画变化的速率,提供提供不同的函数定义变化值相对于时间的变化规则,可以定义各种各样的非线性变换函数,比如加速,减速等。
Android 系统自带了多种Interpolator 可以通过多种动画变化效果:
- AccelerateDecelerateInterpolator 先加速再减速
- AccelerateInterpolator 加速
- AnticipateInterpolator 先回退一小步,然后再迅速前进
- AnticipateOvershootInterpolator 先回退一小步,然后再迅速前进,在超过右边界一小步
- BounceInterpolator 实现弹球效果
- CycleInterpolator 周期运动
- DecelerateInterpolator 减速
- LinearInterpolator 匀速
- OvershootInterpolator 快速前进到右边界上,再往外突出一小步
这些Interpolator 可以应用于任意的Animation中,如TranslateAnimation, RotateAnimation, ScaleAnimation ,AlphaAnimation 等,其插值的对象随Animation 种类不同而不同。比如对于TranslateAnimation来说,插值的对象是位移,对应的动画是平移的速率。对于RotateAnimation来说插值的对象为旋转角度,对应的动画为旋转的速率。
本例介绍使用多种Interpolator 给一个TextView 添加动画。
<TextView
android:id=”@+id/target”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:textSize=”26sp”
android:text=”@string/animation_3_text”/>
本例对应的示例类为Animation3,使用了如下几种Interpolator:
1 |
private static final String[] INTERPOLATORS = {
|
2 |
"Accelerate" , "Decelerate" , "Accelerate/Decelerate" ,
|
3 |
"Anticipate" , "Overshoot" , "Anticipate/Overshoot" ,
|
采用的Animation 类型为TranslateAnimation 平移动画移动TextView:
1 |
final View target = findViewById(R.id.target);
|
2 |
final View targetParent = (View) target.getParent();
|
4 |
Animation a = new TranslateAnimation( 0 .0f,
|
5 |
targetParent.getWidth() - target.getWidth()
|
6 |
- targetParent.getPaddingLeft() -
|
7 |
targetParent.getPaddingRight(), 0 .0f, 0 .0f);
|
10 |
a.setRepeatMode(Animation.RESTART); |
11 |
a.setRepeatCount(Animation.INFINITE); |
15 |
a.setInterpolator(AnimationUtils.loadInterpolator( this ,
|
16 |
android.R.anim.accelerate_decelerate_interpolator));
|
19 |
target.startAnimation(a); |
你也可以自定义Interpolator,只要实现Interpolator接口即可。
From 引路蜂网站(http://www.imobilebbs.com/wordpress/archives/1735)
分享到:
相关推荐
Visualization of Android Animation Interpolators
EaseAnimationInterpolator, 用于Android的动画插值器 可以使用更多的Interpolators EaseAnimationInterpolator用于Android的动画插值器。 可以使用更多的Interpolators 。由 AnimationEasingFunctions 和简化功能。...
Twenty-eight different easing animation interpolators for Android. It does not use the standard 4 param ease signature. Instead it uses a single param which indicates the current linear ratio (0 to 1)...
Thirty different easing animation interpolators for Android. Demo Installation In order to use the library, there are 2 options: 1. Add jar file as library(Recommend) Download the ease-interpolator-...
7.4 Interpolators(插值器) 171 7.5 自定义动画 172 7.6 Android 5.X SVG矢量动画机制 175 7.6.1 标签 175 7.6.2 SVG常用指令 176 7.6.3 SVG编辑器 177 7.6.4 Android中使用SVG 177 7.6.5 SVG动画实例 181 ...
IC-Haus iC-MN插补细分器(Interpolators)pdf,IC-Haus iC-MN插补细分器(Interpolators)
IC-Haus iC-NQ插补细分器(Interpolators)pdf,IC-Haus iC-NQ插补细分器(Interpolators)
IC-Haus iC-MSB插补细分器(Interpolators)pdf,IC-Haus iC-MSB插补细分器(Interpolators)
IC-Haus iC-NG插补细分器(Interpolators)pdf,IC-Haus iC-NG插补细分器(Interpolators)
IC-Haus iC-MG插补细分器(Interpolators)pdf,IC-Haus iC-MG插补细分器(Interpolators)
IC-Haus iC-TW2插补细分器(Interpolators)pdf,IC-Haus iC-TW2插补细分器(Interpolators)
IC-Haus iC-TW3插补细分器(Interpolators)pdf,IC-Haus iC-TW3插补细分器(Interpolators)
IC-Haus iC-TW4插补细分器(Interpolators)pdf,IC-Haus iC-TW4插补细分器(Interpolators)
Rotating text is an Android library that can be used to make text switching painless and beautiful, with the use of interpolators, typefaces and more customisations. Usage Just add the following ...
空间插值 换算器
插补器 基于CPU和GPU的高效计算多维多元插值器库。 要求: pip3>=10.0 ,C ++工具链 构建并安装: pip3 install . 核实: python3 test.py
给资料为B-spline曲线详细解释.B-spline基本特性, B-spline曲線數學模式,B-spline模型特性。
interpolators for sampling rate reduction and sampling rate increase is presented. A set of curves and the necessary relations for optimally designing multistage decimators is also given. It is shown ...
The ProceduralFire sample creates a fire effect by rendering a ... parameters to the pixel shader through texture coordinate interpolators and to vary perturbation maps scrolling speed and offset.
goodtransformer.gif最后附上完整的代码:import android.animation.TimeInterpolator; import android.support.v4.view.ViewPager; import android.view.View; import static java.lang.Math.pow; /**...