Skip to content

Instantly share code, notes, and snippets.

@GRizzi91
Last active August 3, 2021 06:42
Show Gist options
  • Save GRizzi91/99a564141e01a493ab6adcf404c306be to your computer and use it in GitHub Desktop.
Save GRizzi91/99a564141e01a493ab6adcf404c306be to your computer and use it in GitHub Desktop.
ExpandableStackView
val views = mutableListOf<View>()
for (i in 0 until adapter.count) {
val view = adapter.getView(i, null, this)
val cardView = view.findViewById<CardView>(R.id.cardContainer)
view.id = View.generateViewId()
startSet.constrainHeight(view.id, ConstraintSet.WRAP_CONTENT)
endSet.constrainHeight(view.id, ConstraintSet.WRAP_CONTENT)
connectViewToParent(startSet, view)
connectViewToParent(endSet, view)
if (i == 0) {
startSet.connect(
view.id,
ConstraintSet.TOP,
ConstraintSet.PARENT_ID,
ConstraintSet.TOP
)
endSet.connect(
view.id,
ConstraintSet.TOP,
ConstraintSet.PARENT_ID,
ConstraintSet.TOP
)
} else {
views[i - 1].let {
boundTwoViewEnd(endSet, it, view)
if (i == adapter.count - 1) {
endSet.connect(
view.id,
ConstraintSet.BOTTOM,
ConstraintSet.PARENT_ID,
ConstraintSet.BOTTOM,
fromDpToPx(16).toInt()
)
}
boundTwoViewStart(
startSet, it, view,
if (i < 3)
fromDpToPx(8).toInt()
else
0
)
}
}
views.add(view)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment