Phil
Phil

Reputation: 4069

Android Fragment Transaction custom Animation

I'm trying to achieve the animation found here.

Android 3d animation like Google Now Launcher Menu Animation

However, it looks like I can not use the objectAnimator because I'm using the Support Library Fragments. When I tried using the code at the above link, I got an error stating that Unknown animation: objectAnimator.

How can I accomplish an animation like this when adding/removing fragments while still using the Support Library for Fragments?

UPDATE

As per the answer from DeeV below, I've updated the XML Animations for the rest.

gla_back_come.xml

<set xmlns:android="http://schemas.android.com/apk/res/android" android:duration="500">

    <alpha
        android:fromAlpha="1.0"
        android:toAlpha="0.0" />

    <scale
        android:fromXScale="1"
        android:toXScale="0"
        android:fromYScale="1"
        android:toYScale="0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:interpolator="@android:anim/accelerate_decelerate_interpolator" />

</set>

gla_back_gone.xml

<set xmlns:android="http://schemas.android.com/apk/res/android" android:duration="500" >

    <alpha
        android:fromAlpha="0.0"
        android:toAlpha="1.0" />

    <scale
        android:fromXScale="12.0"
        android:toXScale="1.0"
        android:fromYScale="12.0"
        android:toYScale="1.0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:interpolator="@android:anim/accelerate_decelerate_interpolator"/>

</set>

gla_there_come.xml

<set xmlns:android="http://schemas.android.com/apk/res/android" android:duration="500">

    <alpha
        android:fromAlpha="0.0"
        android:toAlpha="1.0" />

    <scale
        android:fromXScale="0.0"
        android:toXScale="1.0"
        android:fromYScale="0.0"
        android:toYScale="1.0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:interpolator="@android:anim/accelerate_decelerate_interpolator"/>

</set>

gla_there_gone.xml

<set xmlns:android="http://schemas.android.com/apk/res/android" android:duration="500" >

    <alpha
        android:fromAlpha="1.0"
        android:toAlpha="0.0"/>

    <scale
        android:fromXScale="1.0"
        android:toXScale="12.0"
        android:fromYScale="1.0"
        android:toYScale="12.0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:interpolator="@android:anim/accelerate_decelerate_interpolator"/>

</set>

Upvotes: 1

Views: 819

Answers (1)

DeeV
DeeV

Reputation: 36035

You would replace the ObjectAnimator with the classic Animation. They can be created in roughly the same fashion. Instead of putting the xml files in the animator resource directory, you would put them in the anim resource directory. The Animations themselves in the xml file are more specificly named. Instead of naming out properties, you name the animation you want to perform:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@[package:]anim/interpolator_resource"
    android:shareInterpolator=["true" | "false"] >
    <alpha
        android:fromAlpha="float"
        android:toAlpha="float" />
    <scale
        android:fromXScale="float"
        android:toXScale="float"
        android:fromYScale="float"
        android:toYScale="float"
        android:pivotX="float"
        android:pivotY="float" />
    <translate
        android:fromXDelta="float"
        android:toXDelta="float"
        android:fromYDelta="float"
        android:toYDelta="float" />
    <rotate
        android:fromDegrees="float"
        android:toDegrees="float"
        android:pivotX="float"
        android:pivotY="float" />
    <set>
        ...
    </set>
</set>

So for example in the answer you posted, the "gla_there_come.xml" would go from this:

<set xmlns:android="http://schemas.android.com/apk/res/android" >

  <objectAnimator
    android:duration="500"
    android:propertyName="alpha"
    android:valueFrom="0.0"
    android:valueTo="1.0" />
  <objectAnimator
    android:duration="500"
    android:interpolator="@android:interpolator/accelerate_decelerate"
    android:propertyName="scaleY"
    android:valueFrom="0"
    android:valueTo="1" />
  <objectAnimator
    android:duration="500"
    android:interpolator="@android:interpolator/accelerate_decelerate"
    android:propertyName="scaleX"
    android:valueFrom="0"
    android:valueTo="1" />

</set>

to this:

<set xmlns:android="http://schemas.android.com/apk/res/android"
     duration="500">

  <alpha
    android:fromAlpha="0.0"
    android:toAlpha="1.0" />

  <scale
    android:fromXScale="0.0"
    android:toXScale="1.0"
    android:fromYScale="0.0"
    android:toYScale="1.0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:interpolator="@android:anim/accelerate_decelerate_interpolator"/>

</set>

Upvotes: 2

Related Questions