Motion Layout reset on navigating between activities

南笙酒味 提交于 2019-12-02 07:36:22

You can add a transition listener to the motion layout & save a flag when the transition is completed. Afterwards, when the activity gets recreated, you can read that flag and use smth like: motionLayout.setState(R.id.end, ConstraintSet.WRAP_CONTENT, ConstraintSet.WRAP_CONTENT) - where R.id.end is the id from constraintSetEnd property.

You have to save/restore the progress of your MotionLayout:

    override fun onSaveInstanceState(outState: Bundle) {
        super.onSaveInstanceState(outState)
        outState.putFloat("progress", motionLayout.progress)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        ...
        if (savedInstanceState != null)
            motionLayout.progress = savedInstanceState.getFloat("progress", 0f)
        ...
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!