我正在尝试在 Kotlin 中对 RelativeLayout 进行子类化,但我坚持使用三个构造函数。
public RelativeLayout(Context context) {}
public RelativeLayout(Context context, AttributeSet attrs) {}
public RelativeLayout(Context context, AttributeSet attrs, int defStyle) {}
我已经尝试过http://devnet.jetbrains.com/message/5482057中描述的过程,但我不知道如何将它们与我的用例相匹配。
希望三个构造函数相互调用,我尝试使用默认值,但它在应用程序启动时崩溃:
class SquareRelativeLayout(context: Context, attrs: AttributeSet? = null, defStyle: Int = 0)
: RelativeLayout(context, attrs!!, defStyle) {}
关于惯用的 Kotlin 方式的任何提示?
[编辑] 我正在使用 Kotlin 0.8.11