Android Kotlin - How to extend ConstraintLayout?
To make sure you don't get any quirks in behavior, you should implement it like this.
class myCL: ConstraintLayout {
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
constructor(context: Context, attrs: AttributeSet?,
@AttrRes defStyleAttr: Int) : super(context, attrs, defStyleAttr)
}
The constructor you really need is the one with all arguments:
class myCL(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) :
ConstraintLayout(context, attrs, defStyleAttr) {
}
if you want to implement all three constructors without much hassle you can use @JvmOverloads
and use sensible defaults.
class myCL @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : ConstraintLayout(context, attrs, defStyleAttr) {
}
see https://developer.android.com/reference/android/support/constraint/ConstraintLayout