簡體   English   中英

Anko中的水平LinearLayout

[英]Horizontal LinearLayout in Anko

在anko / kotlin中進行horizontalLayout的好方法是什么? verticalLayout工作正常 - 可以設置方向,但感覺不對。 不知道我在那里失蹤了什么。

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

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM