如何在 Anko 的 gridLayout 中设置元素的列值和行值?
我试了几个版本,但是这个编译不了:
return UI {
gridLayout() {
columnCount = 2
rowCount = 3
button("1x1") {
}.lparams() { column = 1; row = 1 }
}
}.view
当我这样放置它(作为函数)或作为大括号内的属性时,它说它不能引用 column
或 row
。当我将它们作为参数提供给 lparams 时,它说 不能使用提供的参数调用以下函数中的任何一个
。
最佳答案
如 GridLayout
中所述文档:
Children occupy one or more contiguous cells, as defined by their
rowSpec
andcolumnSpec
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.
您可以像这样使用 rowSpec
和 columnSpec
:
return UI {
gridLayout() {
columnCount = 2
rowCount = 3
button("1x1") {
}.lparams {
rowSpec = GridLayout.spec(1)
columnSpec = GridLayout.spec(1)
}
}
}.view
关于android - Anko - 为 gridLayout 中的元素设置行和列值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38541025/