Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Is it possible to use concurrent interpolators?

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.

like image 381
ilomambo Avatar asked Mar 09 '13 13:03

ilomambo


2 Answers

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

like image 142
Sherif elKhatib Avatar answered Oct 31 '22 20:10

Sherif elKhatib


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.

like image 33
HalR Avatar answered Oct 31 '22 18:10

HalR