Вот что я хотя потом:
Код: Выделить всё
abstract class Foo @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : FrameLayout(context, attrs, defStyleAttr) {
private val myView: View
init {
// todo@patches fix leaking "this"
View.inflate(context, R.layout.view_foo, this)
myView = requireNotNull(findViewById(R.id.my_view))
}
}
Код: Выделить всё
class Bar @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : Foo(context, attrs, defStyleAttr)
Кого-нибудь это немного расстраивает или у кого-нибудь есть совет? Кажется, нередко возникает желание создать один и тот же макет из базового класса.
Подробнее здесь: https://stackoverflow.com/questions/605 ... -inflation