Motion Layout reset on navigating between activities

耗尽温柔 提交于 2020-01-11 14:16:12

问题


I am using motion layout in my mainactivity. It is working proplerly. However when I move to other activities and navigate back to my mainactivity sometimes the activity is reset and the layout is in its starting state.How do I keep this from happening ? Apart from this I also have another question about motion layout which I have asked here


回答1:


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.




回答2:


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)
        ...
    }


来源:https://stackoverflow.com/questions/54002303/motion-layout-reset-on-navigating-between-activities

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