java 带有两个插值器的动画
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11907948/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
animation with two interpolators
提问by ademar111190
I need to do a animation with two interpolators, for example the animation have 1 seconde of duration for 0 sec to 0.5 sec uses accelerate interpolaor ans for 0.5 to 1 sec use bounce interpolator.
我需要用两个插值器制作动画,例如动画的持续时间为 1 秒,持续 0 秒到 0.5 秒,使用加速插值器 0.5 到 1 秒,使用反弹插值器。
have a way for to do this?
有办法做到这一点吗?
回答by 0gravity
You can try something like this:
你可以尝试这样的事情:
<?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>
This uses two interpolators
, the first one is a bounce that moves a view for halve a second. And the second interpolator
is an accelerate interpolator
that moves a view to the right after halve a second has passed, for a duration of one second. Therefore with a total animation time of 1 second. Hope that helps.
这使用了两个interpolators
,第一个是将视图移动半秒的反弹。第二个interpolator
是加速interpolator
,在半秒过去后将视图向右移动,持续时间为一秒。因此,总动画时间为 1 秒。希望有帮助。
回答by ademar111190
I do with one only animation:
我只做一个动画:
Animation animation = new TranslateAnimation(0,100,0,0);
animation.setDuration(1000);
pointerAnimation.setInterpolator(new CustomBounceInterpolator(500));
view.startAnimation(animation);
and the CustomInterpolator Class:
和 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);
}
}
回答by Domi mtz
Hello in the example there is a failure for the anonymous class.
你好在示例中匿名类失败。
its not this:pointerAnimation.setInterpolator(new CustomInterpolator(500));
不是这个:pointerAnimation.setInterpolator(new CustomInterpolator(500));
it is this:pointerAnimation.setInterpolator(new CustomBounceInterpolator(500));
它是这个:pointerAnimation.setInterpolator(new CustomBounceInterpolator(500));
many thanks anyway helped me a lot
非常感谢无论如何帮助了我很多