2

I have 2 fragments that I want to swap between using a card flip animation.

Here is one of my animation files:

<?xml version="1.0" encoding="utf-8"?>
<set>
    <!-- Rotate. -->
    <objectAnimator
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:valueFrom="0"
        android:valueTo="180"
        android:propertyName="rotationY"
        android:interpolator="@android:anim/accelerate_decelerate_interpolator"
        android:duration="@integer/card_flip_time_full" />

    <!-- Half-way through the rotation (see startOffset), set the alpha to 0. -->
    <objectAnimator
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:valueFrom="1.0"
        android:valueTo="0.0"
        android:propertyName="alpha"
        android:startOffset="@integer/card_flip_time_half"
        android:duration="1" />
</set>

I have 4 files like this. They are pretty much taken straight from this Google Demo. I have a minimum sdk of 8, so I am using the highly recommended Nine Old Androids library. However, I am still getting the following error: Uknown animation name: objectAnimator. I can import the package for objectAnimator in my java files, so I am pretty certain I have everything configured properly with the JAR file. Earlier I set the objectAnimator to translate (and changed the attribute values) and it did do an animation, just not the more complicated one I am going for.

Does anyone have any advice on what I might be doing wrong? I am beginning to grasp at straws.

Edit: Just in case it helps, here is my flipCard function:

public void flipSalesCard(FragmentManager fm) {
        if (salesShowingBack) {
            salesShowingBack = false;
            Fragment smallSSF = new SmallSalesSectionFragment();
            FragmentTransaction trans = fm.beginTransaction();
            trans.setCustomAnimations(R.anim.card_flip_left_in, R.anim.card_flip_left_out);
            trans.replace(R.id.SalesInfoFragment, smallSSF);
            trans.addToBackStack(null);
            trans.commit();
            return;
        }
        salesShowingBack = true;

        Fragment expandedSSF = new ExpandedSalesSectionFragment();
        FragmentTransaction trans = fm.beginTransaction();
        trans.setCustomAnimations(R.anim.card_flip_right_in, R.anim.card_flip_right_out);
        trans.replace(R.id.SalesInfoFragment, expandedSSF);
        trans.addToBackStack(null);
        trans.commit();
    }
PFranchise
  • 6,642
  • 11
  • 56
  • 73

3 Answers3

1

Nine Old doesn't work with fragment https://github.com/JakeWharton/NineOldAndroids/issues/43

There's another library for that https://github.com/kedzie/Support_v4_NineOldAndroids but be careful of the caveats as "View animations will no longer work"

inmyth
  • 8,880
  • 4
  • 47
  • 52
0

How about trying to do it programatically?

My answer to: How to animate a slide in notification view that pushes the content view down is an example of this.

Also what happens if you move one of xmlns:android="http://schemas.android.com/apk/res/android" up into the set declaration and remove the other.

Community
  • 1
  • 1
cYrixmorten
  • 7,110
  • 3
  • 25
  • 33
  • If I move that, the autocomplete does not recognize `objectAnimator`. Also, the demo from Nine Old Androids had it there, so I copied them. I could look into doing it programatically, but was hoping to do it like the android example. I need the card flip, not just slide in. – PFranchise Oct 02 '13 at 14:13
0

I spent a few hours on the same problem and came up dry. This StackOverflow answer provided an alternate technique (that doesn't need NineOldAndroid) for implementing the flip rotation which worked out very nicely.

Community
  • 1
  • 1
Abid H. Mujtaba
  • 1,890
  • 1
  • 24
  • 20