在anko / kotlin中进行
horizontalLayout
布局,有什么好的方法吗?verticalLayout
可行 - 可以设置其方向,但感觉不太对。不确定我错过了什么。只需使用linearLayout()
函数即可。
linearLayout {
button("Some button")
button("Another button")
}
是的,LinearLayout
默认是水平的,但我倾向于更加明确并使用单独的 horizontalLayout
函数。
你可以将 horizontalLayout
函数简单地添加到你的项目中:
val HORIZONTAL_LAYOUT_FACTORY = { ctx: Context ->
val view = _LinearLayout(ctx)
view.orientation = LinearLayout.HORIZONTAL
view
}
inline fun ViewManager.horizontalLayout(@StyleRes theme: Int = 0, init: _LinearLayout.() -> Unit): _LinearLayout {
return ankoView(HORIZONTAL_LAYOUT_FACTORY, theme, init)
}
我在 Anko 上提出了一个功能请求:https://github.com/Kotlin/anko/issues/413