Anko中的水平LinearLayout

12
在anko / kotlin中进行horizontalLayout布局,有什么好的方法吗?verticalLayout可行 - 可以设置其方向,但感觉不太对。不确定我错过了什么。
2个回答

18

只需使用linearLayout()函数即可。

linearLayout {
    button("Some button")
    button("Another button")
}

1
是的,一开始有点困惑 :) - Antek

0

是的,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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接