ade*_*190 8 java animation android interpolation
我需要用两个插值器做一个动画,例如动画有1秒的持续时间,持续0秒到0.5秒,使用加速插值法0.5到1秒使用反弹插值器.
有办法做到这一点?
0gr*_*ity 12
你可以尝试这样的事情:
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:interpolator="@android:anim/bounce_interpolator"
android:fromYDelta="0%p"
android:toYDelta="100"
android:duration="500"/>
<translate
android:interpolator = "@android:anim/accelerate_interpolator"
android:fromYDelta="100"
android:toYDelta="100"
android:fromXDelta="0"
android:toXDelta="100"
android:startOffset="500"
android:duration="1000"/>
</set>
Run Code Online (Sandbox Code Playgroud)
这使用两个interpolators,第一个是反弹,将视图移动一半减半.第二个interpolator是加速interpolator,在一秒钟过了一半之后将视图向右移动,持续时间为一秒.因此总动画时间为1秒.希望有所帮助.
ade*_*190 11
我只使用一个动画:
Animation animation = new TranslateAnimation(0,100,0,0);
animation.setDuration(1000);
pointerAnimation.setInterpolator(new CustomBounceInterpolator(500));
view.startAnimation(animation);
Run Code Online (Sandbox Code Playgroud)
和CustomInterpolator类:
public class CustomBounceInterpolator implements Interpolator {
private float timeDivider;
private AccelerateInterpolator a;
private BounceInterpolator b;
public CustomBounceInterpolator(float timeDivider) {
a = new AccelerateInterpolator();
b = new BounceInterpolator();
this.timeDivider = timeDivider;
}
public float getInterpolation(float t) {
if (t < timeDivider)
return a.getInterpolation(t);
else
return b.getInterpolation(t);
}
}
Run Code Online (Sandbox Code Playgroud)