Horizontal LinearLayout in Anko
Asked Answered
L

2

12

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.

Lignify answered 30/4, 2015 at 11:31 Comment(0)
B
18

Just use a linearLayout() function instead.

linearLayout {
    button("Some button")
    button("Another button")
}
Bothwell answered 1/5, 2015 at 21:20 Comment(1)
yeah, it was a bit confusing at first :)Hosfmann
F
0

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

Fitment answered 17/6, 2017 at 8:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.