How to set explode transition with xml file
Asked Answered
P

1

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?

Pacorro answered 27/1, 2018 at 7:57 Comment(3)
How's you using this xml in your code ?Gratin
i'm using it in my style <item name="android:windowAnimationStyle">@transition/explode</item>Pacorro
You have to create a WindowAnimationTransition style in your style.xml(with android:windowEnterAnimation and android:windowExitAnimation). Then use this style as windowAnimationStyle.Gratin
G
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());
Gratin answered 27/1, 2018 at 8:19 Comment(5)
getting error Unknown animation name: transitionManager, i think my xml code is not correct, can you provide correct explode xml filePacorro
@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 .Karisakarissa
@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?Gratin
@HeisenBrg, thanks for courtesy , this piece of code is working for me,Karisakarissa
@HeisenBrg can i have your explanation .Karisakarissa

© 2022 - 2024 — McMap. All rights reserved.