7

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?

MJakhongir
  • 2,101
  • 2
  • 16
  • 27

1 Answers1

17

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());
Aditya
  • 3,525
  • 1
  • 31
  • 38
  • getting error Unknown animation name: transitionManager, i think my xml code is not correct, can you provide correct explode xml file – MJakhongir Jan 27 '18 at 09:18
  • 2
    @HeisenBrg, i would like to ask few questions here 1) in ActivityOptions or anywhere else , we haven't wrote any piece of code that reflects that we are using that particular explode transition , How android knows we want to use that transition . 2)If we make more transitions in the transitions folder how can we specify which transition would happen for which activity ? 3)Can we make transition between activities just by using Explode explode = new Explode() in java ? if so how can we accomplish that. i would be thankful for the answers . – Hissaan Ali Jan 15 '19 at 17:55
  • 1
    @SyedHissaan I will give you the explanation for all your question. But first, I want to know that is this piece of code working for you or not? – Aditya Jan 16 '19 at 05:26
  • @HeisenBrg, thanks for courtesy , this piece of code is working for me, – Hissaan Ali Jan 16 '19 at 05:37
  • @HeisenBrg can i have your explanation . – Hissaan Ali Jan 20 '19 at 19:42