View ExpandableStackViewAdapter.kt
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 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() |
View card.xml
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
<?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
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) { } | |
} |
View ExpandableStackView.kt
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
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
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() |
View ExpandableStackView.kt
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
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
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
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
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
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
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
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
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
fun ConstraintSet.setCardElevation(cardView: CardView, elevation: Float) { | |
getConstraint(cardView.id)?.let { | |
it.mCustomConstraints["CardElevation"] = ConstraintAttribute( | |
"CardElevation", | |
ConstraintAttribute.AttributeType.DIMENSION_TYPE, | |
elevation | |
) | |
} | |
} |
OlderNewer