ActivityOptionsCompat.makeSceneTransitionAnimation with custom duration

我与影子孤独终老i 提交于 2020-01-02 06:49:18

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!