Skip to content

Instantly share code, notes, and snippets.

Created November 30, 2017 12:31
What would you like to do?
class CustView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0)
: ConstraintLayout(context, attrs, defStyleAttr) {
var buttonTapped: (() -> Unit)? = null
init {
val view = LayoutInflater.from(context).inflate(R.layout.custom_view, this, false)
val set = ConstraintSet()
set.match(view, this)
button.setOnClickListener {
fun ConstraintSet.match(view: View, parentView: View) {
this.connect(, ConstraintSet.TOP,, ConstraintSet.TOP)
this.connect(, ConstraintSet.START,, ConstraintSet.START)
this.connect(, ConstraintSet.END,, ConstraintSet.END)
this.connect(, ConstraintSet.BOTTOM,, ConstraintSet.BOTTOM)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment