Anko - 为 gridLayout 中的元素设置行和列值

Anko - Setting row and column value for an element in gridLayout

如何在 Anko 的 gridLayout 中设置元素的列值和行值?

我试了几个版本,但是这个编译不了:

   return UI {
        gridLayout() {
            columnCount = 2
            rowCount = 3
            button("1x1") {

            }.lparams() { column = 1; row = 1 }
        }
    }.view

当我像这样(作为函数)或作为大括号内的属性时,它说它不能引用 columnrow。当我将它们作为 lparams 的参数提供时,它说 none of the following functions can be called with arguments supplied.

GridLayout 文档中所述:

Children occupy one or more contiguous cells, as defined by their rowSpec and columnSpec layout parameters. Each spec defines the set of rows or columns that are to be occupied; and how children should be aligned within the resulting group of cells.

您可以像这样使用 rowSpeccolumnSpec

return UI {
    gridLayout() {
        columnCount = 2
        rowCount = 3
        button("1x1") {

        }.lparams {
            rowSpec = GridLayout.spec(1)
            columnSpec = GridLayout.spec(1)
        }
    }
}.view