Skip to content

Instantly share code, notes, and snippets.

View ExpandableStackViewAdapter.kt
class ExpandableStackViewAdapter(
private val models: List<String>,
private val context: Context
) : BaseAdapter() {
override fun getCount(): Int = models.size
override fun getItem(position: Int): String = models[position]
override fun getItemId(position: Int): Long = position.toLong()
@GRizzi91
GRizzi91 / card.xml
Last active Aug 1, 2021
ExpandableCardViewLayout
View card.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
app:cardCornerRadius="16dp"
android:layout_width="300dp"
app:cardUseCompatPadding="true"
android:layout_height="200dp"
android:layout_margin="16dp"
android:id="@+id/cardContainer">
View ExpandableStackView.kt
class ExpandableStackView @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : MotionLayout(context, attrs, defStyleAttr) {
fun setAdapter(adapter: BaseAdapter) { }
}
View ExpandableStackView.kt
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()
View ExpandableStackView.kt
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()
View ExpandableStackView.kt
for (i in 0 until adapter.count) {
val view = adapter.getView(i, null, this)
view.id = View.generateViewId()
startSet.constrainHeight(view.id, ConstraintSet.WRAP_CONTENT)
endSet.constrainHeight(view.id, ConstraintSet.WRAP_CONTENT)
connectViewToParent(startSet, view)
connectViewToParent(endSet, view)
}
View ExpandableStackView.kt
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)
View ExpandableStackView.kt
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()
View ExpandableStackView.kt
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()
View ConstraintSetExtension.kt
fun ConstraintSet.setCardElevation(cardView: CardView, elevation: Float) {
getConstraint(cardView.id)?.let {
it.mCustomConstraints["CardElevation"] = ConstraintAttribute(
"CardElevation",
ConstraintAttribute.AttributeType.DIMENSION_TYPE,
elevation
)
}
}