jason
jason

Reputation: 3962

Android transition animation is not working

Android transition is same for explode and slide.Actually I don't think its animating. Also duration is not 6 seconds. How can I fix it?

Code taken from here.

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);

        Transition ts = new Slide();  //Slide(); //Explode();

        ts.setDuration(6000);
        getWindow().setEnterTransition( ts );
        getWindow().setExitTransition( ts );
        setContentView(R.layout.activity_main_activity);



    }




    @Override
    public void onBackPressed() {
        super.onBackPressed();
        finishAfterTransition();
    }

Style-v21.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="BaseAppTheme" parent="android:Theme.Material.Light">
        <item name="android:colorControlHighlight">#0000AA</item>
        <item name="android:navigationBarColor">#0000AA</item>
        <item name="android:colorPrimaryDark">#0000AA</item>
        <item name="android:colorPrimary">#0000FF</item>
        <item name="android:colorAccent">#00FF00</item>
        <item name="android:windowBackground">@android:color/black</item>
        <item name="android:textColorPrimary">@android:color/white</item>

        <item name="android:windowContentTransitions">true</item>
        <item name="android:windowAllowEnterTransitionOverlap">true</item>

        <!-- specify enter and exit transitions -->
        <item name="android:windowEnterTransition">@transition/explode</item>
        <item name="android:windowExitTransition">@transition/explode</item>
    </style>
</resources>

Upvotes: 9

Views: 15981

Answers (4)

Boy
Boy

Reputation: 7497

I found out that I need to really do

ActivityOptionsCompat activityOptionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation(activity, test, "transition_name");
ActivityCompat.startActivity(TourAndLoginActivity.this, new Intent(TourAndLoginActivity.this, LoginActivity.class), activityOptionsCompat.toBundle());

Still puzzling, but I don't know why we need to have a shared object to get the enter / exit transition. If I supply null instead of the ActivityOptionsCompat, there is no transition

Upvotes: 4

Cletus Ajibade
Cletus Ajibade

Reputation: 1590

In my own case, for some reason, Transition Animation was off in the developer options of my android device.

Just go to Settings -> Developer Options -> Transition animation scale: set to Animation scale 1x

Upvotes: 18

nilsi
nilsi

Reputation: 10761

Don't forget to apply the theme for the activity or the whole package in your AndroidManifest.xml.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="android.package"
android:theme="@style/BaseAppTheme">
    ....
    ....
</manifest>

Upvotes: 3

user4728480
user4728480

Reputation:

You can use this to start a new activity with transition

startActivity(new Intent(this, NewActivity.class));
overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);

Create file res/anim/slide_in_right.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
     android:shareInterpolator="false" >
     <translate android:duration="1000" android:fromXDelta="100%" android:toXDelta="0%" />
    <alpha android:duration="1000" android:fromAlpha="0.0" android:toAlpha="1.0" />
</set>

Create file res/anim/slide_out_left.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
     android:shareInterpolator="false" >
     <translate android:duration="2000" android:fromXDelta="0%" android:toXDelta="-100%"/>
     <alpha android:duration="2000" android:fromAlpha="1.0" android:toAlpha="0.0" />
</set>

Upvotes: 5

Related Questions