问题
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());
回答1:
You can set the desired duration in the new started activity, by adding:
ChangeBounds bounds = new ChangeBounds();
bounds.setDuration(2000);
getWindow().setSharedElementEnterTransition(bounds);
回答2:
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);
来源:https://stackoverflow.com/questions/35715144/activityoptionscompat-makescenetransitionanimation-with-custom-duration