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

标签 android kotlin anko

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

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

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

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

当我这样放置它(作为函数)或作为大括号内的属性时,它说它不能引用 columnrow。当我将它们作为参数提供给 lparams 时,它说 不能使用提供的参数调用以下函数中的任何一个

最佳答案

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

关于android - Anko - 为 gridLayout 中的元素设置行和列值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38541025/

相关文章:

expression-trees - Kotlin 是否支持表达式树?

Android Kotlin 使用 anko doAsync 在 ui 线程上处理异常

android - 当我在输入一个完整的单词后按空格键时,AutoCompleteTextView 不显示下拉菜单

android - 地理编码减慢一切?

java - 单击时如何从微调器下拉列表中创建第二个 Activity ?

java - 为什么 Kotlin 的内部可访问性与 Java 的包私有(private)可访问性不同?

java - 在android中滚动图像

spring-boot - 如何并行调用多个Spring Webclient并等待结果?

android - 如何使用 Anko DSL 设置 NavigationView 标题 View ?

android - Anko 忽略样式中定义的 layout_margin