What is a good way to do a horizontalLayout
in anko / kotlin ? verticalLayout
works fine - could set orientation on it but it feels wrong. Not sure what I am missing there.
Horizontal LinearLayout in Anko
Just use a linearLayout()
function instead.
linearLayout {
button("Some button")
button("Another button")
}
yeah, it was a bit confusing at first :) –
Hosfmann
Yeah, LinearLayout
is by default horizontal, but I tend to be extra specific and rather use a separate horizontalLayout
function for that.
You can simply add the horizontalLayout
function to your project:
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)
}
I have opened a feature request at Anko: https://github.com/Kotlin/anko/issues/413
© 2022 - 2024 — McMap. All rights reserved.