20 lines
748 B
Kotlin
20 lines
748 B
Kotlin
package com.gh.common.view
|
|
|
|
import android.content.Context
|
|
import android.util.AttributeSet
|
|
import androidx.constraintlayout.motion.widget.MotionLayout
|
|
import com.google.android.material.appbar.AppBarLayout
|
|
|
|
class CollapsingMotionLayout @JvmOverloads constructor(
|
|
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
|
|
) : MotionLayout(context, attrs, defStyleAttr), AppBarLayout.OnOffsetChangedListener {
|
|
|
|
override fun onOffsetChanged(appBarLayout: AppBarLayout?, verticalOffset: Int) {
|
|
progress = -verticalOffset / appBarLayout?.totalScrollRange?.toFloat()!!
|
|
}
|
|
|
|
override fun onAttachedToWindow() {
|
|
super.onAttachedToWindow()
|
|
(parent as? AppBarLayout)?.addOnOffsetChangedListener(this)
|
|
}
|
|
} |