Polaric
Polaric

Reputation: 61

Android SharedElement transitions not working

I have a list of cardViews with two TextViews inside, when one of the card views is clicked, a detail view acitivty that is composed of the same card view structure plus one webview. My intention is for the card to expand out of the list as the new activity opens and the text to move smoothly into place, as of right now, I can't seem to get the card view alone to animate, it just flickers and then fades into place.

Launching the new activity:

    ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(this,cardview,"cardview");
        Intent i = new Intent(this,DetailView.class);
        startActivity(i,options.toBundle());

Animation part of styles.xml (v1)

    <item name="android:windowContentTransitions">true</item>
    <item name="android:windowSharedElementEnterTransition">@transition/cardtransition</item>
    <item name="android:windowAllowEnterTransitionOverlap">true</item>
    <item name="android:windowAllowReturnTransitionOverlap">true</item>

cardtransition.xml

    <transitionSet xmlns:android="http://schemas.android.com/apk/res/android" >
<changeBounds android:duration="40000"/>
<changeTransform android:duration="40000" />
</transitionSet>

Upvotes: 2

Views: 781

Answers (1)

Polaric
Polaric

Reputation: 61

I've figured it out, when using shared element transitions in any kind of list, you cant use android:transitionName in the XML layout of the list item, because then every item in the list has the same transitionName. You must dynamically set the transition name at runtime in code for the specific item you want to be animated.

Upvotes: 4

Related Questions