Created
August 2, 2021 13:50
-
-
Save GRizzi91/5e6a6245a6185a214e77be855227f277 to your computer and use it in GitHub Desktop.
ExpandableStackView
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ExpandableStackView @JvmOverloads constructor( | |
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 | |
) : MotionLayout(context, attrs, defStyleAttr) { | |
fun setAdapter(adapter: BaseAdapter) { | |
val scene = MotionScene(this) | |
val startSetId = View.generateViewId() | |
val startSet = ConstraintSet() | |
startSet.clone(this) | |
val endSetId = View.generateViewId() | |
val endSet = ConstraintSet() | |
endSet.clone(this) | |
val transitionId = View.generateViewId() | |
val transaction = TransitionBuilder.buildTransition( | |
scene, | |
transitionId, | |
startSetId, startSet, | |
endSetId, endSet | |
) | |
transaction.duration = 1000 | |
scene.addTransition(transaction) | |
scene.setTransition(transaction) | |
setScene(scene) | |
setTransition(transitionId) | |
} | |
private fun boundTwoViewEnd( | |
constraintSet: ConstraintSet, | |
firstView: View, | |
secondView: View | |
) { | |
constraintSet.connect( | |
secondView.id, | |
ConstraintSet.TOP, | |
firstView.id, | |
ConstraintSet.BOTTOM, | |
fromDpToPx(16).toInt() | |
) | |
} | |
private fun boundTwoViewStart( | |
constraintSet: ConstraintSet, | |
firstView: View, | |
secondView: View, | |
marginBottom: Int | |
) { | |
constraintSet.connect( | |
secondView.id, | |
ConstraintSet.TOP, | |
firstView.id, | |
ConstraintSet.TOP, | |
marginBottom | |
) | |
} | |
private fun connectViewToParent( | |
constraintSet: ConstraintSet, | |
firstView: View | |
) { | |
constraintSet.connect( | |
firstView.id, | |
ConstraintSet.START, | |
ConstraintSet.PARENT_ID, | |
ConstraintSet.START | |
) | |
constraintSet.connect( | |
firstView.id, | |
ConstraintSet.END, | |
ConstraintSet.PARENT_ID, | |
ConstraintSet.END | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment