Anko 0.8 - unresolved lparams reference

大城市里の小女人 提交于 2019-12-05 07:59:29

Apparently lparams is still there, but cannot be used as an extension function for the outermost layout:

So the following code fails:

override fun createView(ui: AnkoContext<ReviewsFragment>) = ui.apply {
    verticalLayout {
        // Layout elements here
    }.lparams { 
        // Layout params here
    }
}.view

But this compiles fine:

override fun createView(ui: AnkoContext<ReviewsFragment>) = ui.apply {
    verticalLayout {
        lparams {
            // Layout params here
        }

        // Layout elements here
        verticalLayout { }.lparams {
            // lparams works fine if there is a parent layout
        }
    } 
}.view

It's worth noting that using the non-tailing version of lparams is discouraged for inner layouts: it will create the wrong sublass of LayoutParams when the nested layouts are of different types. For a complete discussion, see this GitHub Issue.

Why don't you use the most recent way to write createView() method? I think the following solves your problem:

override fun createView(ui: AnkoContext<ReviewsFragment>) : View = with(ui) { 
    return verticalLayout { 
    // Layout elements here 
    }.lparams { 
    // Layout params here 
    } 
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!