I have a set of two animations, both animations run together using the overshoot interpolator
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/overshoot_interpolator" >
<translate
android:duration="6000"
android:fromXDelta="100%" android:toXDelta="0%" />
<scale
android:duration="6000"
android:fromXScale="1.0" android:toXScale="0.6"
android:pivotX="0"
android:fromYScale="1.0" android:toYScale="1.0"
android:repeatCount="1"
android:repeatMode="reverse" />
</set>
I want the translate
animation to overshoot, and the scale
animation to accelerate.
I tried to do this, but it does not work:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:interpolator="@android:anim/overshoot_interpolator"
android:duration="6000"
android:fromXDelta="100%" android:toXDelta="0%" />
<scale
android:interpolator="@android:anim/accelerate_interpolator"
android:duration="6000"
android:fromXScale="1.0" android:toXScale="0.6"
android:pivotX="0"
android:fromYScale="1.0" android:toYScale="1.0"
android:repeatCount="1"
android:repeatMode="reverse" />
</set>
It seems as if only one interpolator can be active at a given time for all animations being performed on a single object.
This is only guess work. I remember that one of AnimationSet
's constructors can take an argument, namely shareInterpolator.
Judging by the name of the parameter, this probably should be set to false in you case. Right now, it should be using the default "value". This default value is most probably true because your animations are not having different interpolators although you specified a different one for each.
To confirm, the source code of AnimationSet has the following line to assign a value for shareInterpolator (from xml):
setFlag(PROPERTY_SHARE_INTERPOLATOR_MASK,
a.getBoolean(com.android.internal.R.styleable.AnimationSet_shareInterpolator
, true));
This clearly means that if this boolean is not specified, it will default to true.
Solution
To fix your problem, I suppose you should specify it using this "R.styleable.AnimationSet_shareInterpolator". This merely means adding android:shareInterpolator="false"
to your <set>
elements
I put split the animations and put one on an ImageView
and the other on a RelativeLayout
that was containing the image view.
Translator
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:interpolator="@android:anim/overshoot_interpolator"
android:duration="6000"
android:fromXDelta="100%" android:toXDelta="0%" />
</set>
Scalor
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<scale
android:interpolator="@android:anim/accelerate_interpolator"
android:duration="6000"
android:fromXScale="1.0" android:toXScale="0.6"
android:pivotX="0"
android:fromYScale="1.0" android:toYScale="1.0"
android:repeatCount="1"
android:repeatMode="reverse" />
</set>
xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/previousItem"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:onClick="goToPreviousItem"
android:layout_margin="@dimen/float_from_edges"
android:layout_width="wrap_content"
>
<ImageView android:id="@+id/previousItemArrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/arrow_left"
/>
</RelativeLayout>
And the source code to instigate it:
RelativeLayout previousItemButton = (RelativeLayout)findViewById(R.id.previousItem);
ImageView myButton = (ImageView)findViewById(R.id.previousItemArrow);
Animation translator =
AnimationUtils.loadAnimation(this, R.anim.translator);
myButton.startAnimation(translator);
Animation scalor =
AnimationUtils.loadAnimation(this, R.anim.scalor);
previousItemButton.startAnimation(scalor);
I thought it looked pretty good. I'm not sure what effect you were hoping for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With