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?

Floern
  • 33,559
  • 24
  • 104
  • 119
Alessandro Roaro
  • 4,665
  • 6
  • 29
  • 48
  • I suspect `` tag is the main reason for this weird behavior. If you remove the `` 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. – blizzard Sep 12 '15 at 22:05

1 Answers1

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());
JItesh SUvarna
  • 663
  • 7
  • 17