Motion Layout reset on navigating between activities

前端 未结 4 769
鱼传尺愫
鱼传尺愫 2021-01-19 04:23

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

4条回答
  •  囚心锁ツ
    2021-01-19 04:54

    class ExtMotionLayout : MotionLayout {
        constructor(context: Context) : super(context)
        constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
        constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr)
    
        override fun onSaveInstanceState(): Parcelable? {
            return SavedState(progress, super.onSaveInstanceState())
        }
    
        override fun onRestoreInstanceState(state: Parcelable?) {
            if (state is SavedState) {
                progress = state.progress
                super.onRestoreInstanceState(state.superState)
            } else super.onRestoreInstanceState(state)
        }
    
        class SavedState : BaseSavedState {
            val progress: Float
    
            constructor(progress: Float, source: Parcelable?) : super(source) {
                this.progress = progress
            }
    
            constructor(superState: Parcel) : super(superState) {
                progress = superState.readFloat()
            }
    
            override fun writeToParcel(out: Parcel, flags: Int) {
                super.writeToParcel(out, flags)
                out.writeFloat(progress)
            }
        }
    }
    

提交回复
热议问题