Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set explode transition with xml file

I'm trying to setEnterTransition with explode.xml file.

i tried this

<?xml version="1.0" encoding="utf-8"?>
<transitionManager xmlns:android="http://schemas.android.com/apk/res/android">
    <transition android:transition="@transition/explode" />
</transitionManager>

and this

<?xml version="1.0" encoding="utf-8"?>
    <transitionSet xmlns:android="http://schemas.android.com/apk/res/android">
        <explode
            android:duration="500"
            android:interpolator="@android:interpolator/bounce" />
 </transitionSet>

but explode animation did not work, any ideas?

like image 887
MJakhongir Avatar asked Jan 27 '18 07:01

MJakhongir


1 Answers

Firstly, create a Transition XML for explode transition named explode.xml in res/transition folder. As,

<?xml version="1.0" encoding="utf-8"?>
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android">
    <explode
        android:duration="320" />
</transitionSet>

Then, in styles.xml in your AppTheme set android:windowContentTransitions as true and reference the explode transition for Enter and Exit like below:

<item name="android:windowContentTransitions">true</item>
<item name="android:windowEnterTransition">@transition/explode</item>
<item name="android:windowExitTransition">@transition/explode</item>

Now start your activity as,

ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(this);
Intent intent = new Intent(MainActivity.this, SecondActivitiy.class);
startActivity(intent, options.toBundle());
like image 145
Aditya Avatar answered Nov 08 '22 11:11

Aditya