Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Activity transition not performed (Lollipop)

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?

like image 252
Alessandro Roaro Avatar asked Aug 24 '15 04:08

Alessandro Roaro


1 Answers

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());
like image 195
JItesh SUvarna Avatar answered Nov 19 '22 17:11

JItesh SUvarna