问题 Anko中的Horizo​​ntal LinearLayout


做一个好方法是什么 horizontalLayout 在anko / kotlin? verticalLayout 工作正常 - 可以设置方向,但感觉不对。不知道我在那里失踪了什么。


1303
2018-04-30 11:31


起源



答案:


只需使用一个 linearLayout() 功能而不是。

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

15
2018-05-01 21:20



是的,起初有点令人困惑:) - Antek


答案:


只需使用一个 linearLayout() 功能而不是。

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

15
2018-05-01 21:20



是的,起初有点令人困惑:) - Antek


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


0
2018-06-17 08:40