Horizontal LinearLayout in Anko

What is a good way to do horizontalLayout in anko / kotlin? verticalLayout works great - it can set the orientation on it, but it feels wrong. Not sure what I miss there.

+8
android kotlin anko
source share
2 answers

Just use the linearLayout() function.

 linearLayout { button("Some button") button("Another button") } 
+10
source share

Yes, LinearLayout is horizontal by default, but I tend to be more specific and rather use a separate horizontalLayout function for this.

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 opened a function request in Anko: https://github.com/Kotlin/anko/issues/413

0
source share

All Articles