Reputation: 2258
I'm making a scene transition for devices with API level 20+. It is working fine, but I want to set custom duration to make the transition. Is it possible ??
My code:
ActivityOptionsCompat options =
ActivityOptionsCompat.makeSceneTransitionAnimation(this,
viewStart,
transitionName
);
ActivityCompat.startActivity(this, detailsIntent, options.toBundle());
Upvotes: 7
Views: 7768
Reputation: 245
Here's a simple one-liner in Kotlin, just put it in the onCreate()
of the Activity you're starting: window.sharedElementEnterTransition.duration = 300
Upvotes: 0
Reputation: 1828
You can set the desired duration in the new started activity, by adding:
ChangeBounds bounds = new ChangeBounds();
bounds.setDuration(2000);
getWindow().setSharedElementEnterTransition(bounds);
Upvotes: 13
Reputation: 1176
Please read #5 of Mr saeed's link. Or you can try by java code:
Window window = getWindow();
TransitionSet set = new TransitionSet();
set.addTransition(new ChangeImageTransform());
set.addTransition(new ChangeBounds());
set.setDuration(duration);
set.addListener(yourTransitionListener)
window.setSharedElementEnterTransition(set);
Upvotes: 0