Activity transition not performed (Lollipop)
Asked Answered
H

1

16

I am animating a transition between activity X and activity Y.
X contains a list with images, and when an image is clicked is expanded and "zoomed" in activity Y.
So, this image is a share element between X and Y. I have set its transitionName property in the XML layouts.
This is the code that starts activity Y:

ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(this, clickedImage, clickedImage.getTransitionName());
startActivityForResult(intent, OPEN_PICTURE_REQUEST, options.toBundle());

Until here, everything works fine. However, I also want to animate the layout of activity Y when is entered.
To do so, I have defined the transition in a XML file (picture_enter.xml):

<transitionSet xmlns:android="http://schemas.android.com/apk/res/android"
    android:transitionOrdering="together">

    <transition
        class="android.transition.Explode"
        android:startDelay="200">
        <targets>
            <target android:targetId="@+id/top_toolbar_container" />
        </targets>
    </transition>

</transitionSet>

Finally, in the onCreate of activity Y I initalize the transition:

TransitionInflater inflater = TransitionInflater.from(this);
Transition transition = inflater.inflateTransition(R.transition.picture_enter);
Window window = getWindow();
window.setEnterTransition(transition);

But this is never performed. Only the "zoom" effect of the image works as it should. I have also tried defining the transition programmatically.
Any suggestions?

Hugibert answered 24/8, 2015 at 4:34 Comment(1)
I suspect <targets> tag is the main reason for this weird behavior. If you remove the <targets> tag, by default transition will be applied to activity Y. Minor suggestion: You can directly define transitions like explode, slide etc inside transitionSet, the transition tag is mainly used to define custom transitions.Denison
I
4

You should be using application theme with the following window tags :

<style name="CustomActionBarTheme" parent="Theme.AppCompat.Light.NoActionBar">

    <!-- enable window content transitions -->
    <item name="android:windowContentTransitions">true</item>

    <!-- enable overlapping of exiting and entering activities -->
    <item name="android:windowAllowEnterTransitionOverlap">true</item>
    <item name="android:windowAllowReturnTransitionOverlap">true</item>
</style>

In Mainfest file , inside application tag use android:theme="@style/CustomActionBarTheme"

In Activity X ,

       ActivityOptionsCompat options = ActivityOptionsCompat
                                    .makeSceneTransitionAnimation(activity,img_pic, "img_pic");

where "img_pic" is android:transitionName="img_pic" in both layout files of Activity X and Activity Y.

NOTE : android:transitionName values should be same for the transition to take place.

Opening Activity Y with ActivityOptionsCompat or ActivityOptions ,

Intent intent = new Intent(context,Activity_Y.class);
startActivity(intent, options.toBundle());
Inoffensive answered 8/9, 2015 at 10:30 Comment(2)
I had already tried to add those values to the styles.xml but still didn't work, thanks anywayHugibert
BTW. The styles.xml file must be under drawable-v21 folder.Inoffensive

© 2022 - 2024 — McMap. All rights reserved.