Reputation: 14505
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.
have a way for to do this?
Upvotes: 8
Views: 13814
Reputation: 3
This post is already old, but for the next one who lands here:
The Example from @ademar111190 isn't quite right.
In getInterpolation(float t)
, t needs to be between 0
and 1
. This is the Timespan for the Animation.
The used input 500 will completely ignore the 2nd Interpolator.
Here the link to the Documentation: Time Interpolator
Upvotes: 0
Reputation: 14505
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:
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);
}
}
Upvotes: 11
Reputation: 91
Hello in the example there is a failure for the anonymous class.
its not this:pointerAnimation.setInterpolator(new CustomInterpolator(500));
it is this:pointerAnimation.setInterpolator(new CustomBounceInterpolator(500));
many thanks anyway helped me a lot
Upvotes: 3
Reputation: 2762
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.
Upvotes: 13