未解决的参考:Anko 0.10.6中的verticalLayout的lparams

时间:2018-09-30 06:07:45

标签: android kotlin anko

我看过Anko 0.8 - unresolved lparams reference,但是我没有在最外部的布局中使用lparams,就像在该链接中那样。

我在以下代码中得到“未解决的参考:lparams”(Android Studio中没有导入建议)。关于我错过和/或忽略的内容有什么想法吗?

class LoginActivityUi: AnkoComponent<LoginActivity> {

    override fun createView(ui: AnkoContext<LoginActivity>): View = with(ui) {
        verticalLayout {
            backgroundColorResource = R.color.background_page

            textView{
                text = "ASDF"
            }.lparams{

            }
        }
    }

}

这是我的依赖项($ kotlin_version为1.2.71,$ anko_version为0.10.6):

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'

testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

implementation "org.jetbrains.anko:anko-commons:$anko_version"

// Appcompat-v7 (only Anko Commons)
implementation "org.jetbrains.anko:anko-appcompat-v7-commons:$anko_version"

// Appcompat-v7 (Anko Layouts)
implementation "org.jetbrains.anko:anko-appcompat-v7:$anko_version"
implementation "org.jetbrains.anko:anko-coroutines:$anko_version"

// Anko Layouts
implementation "org.jetbrains.anko:anko-sdk15:$anko_version" // sdk15, sdk19, sdk21, sdk23 are also available
implementation "org.jetbrains.anko:anko-appcompat-v7:$anko_version"

// Coroutine listeners for Anko Layouts
implementation "org.jetbrains.anko:anko-sdk15-coroutines:$anko_version"
implementation "org.jetbrains.anko:anko-appcompat-v7-coroutines:$anko_version"

// CardView-v7
implementation "org.jetbrains.anko:anko-cardview-v7:$anko_version"

// Design
implementation "org.jetbrains.anko:anko-design:$anko_version"
implementation "org.jetbrains.anko:anko-design-coroutines:$anko_version"

// GridLayout-v7
implementation "org.jetbrains.anko:anko-gridlayout-v7:$anko_version"

// Percent
implementation "org.jetbrains.anko:anko-percent:$anko_version"

// RecyclerView-v7
implementation "org.jetbrains.anko:anko-recyclerview-v7:$anko_version"
implementation "org.jetbrains.anko:anko-recyclerview-v7-coroutines:$anko_version"

// Support-v4 (only Anko Commons)
implementation "org.jetbrains.anko:anko-support-v4-commons:$anko_version"

// Support-v4 (Anko Layouts)
implementation "org.jetbrains.anko:anko-support-v4:$anko_version"

// ConstraintLayout
implementation "org.jetbrains.anko:anko-constraint-layout:$anko_version"
}

1 个答案:

答案 0 :(得分:2)

好的,所以...正如您在this diff中所见,从Anko 0.10.6开始,verticalLayout方法已被修改为采用LinearLayout.() -> Unit类型的初始化器lambda。前_LinearLayout.() -> Unit类型中的一种。下划线的_LinearLayout类是定义您正在寻找的lparams方法的类,这就是为什么由于此更改而使它丢失的原因。

此重大更改已经存在一个公开的问题:https://github.com/Kotlin/anko/issues/673

与此同时,您可以坚持使用0.10.5,也可以将linearLayout的使用方向明确:

linearLayout {
    orientation = LinearLayout.VERTICAL
    backgroundColorResource = R.color.background_page

    textView {
        text = "ASDF"
    }.lparams {

    }
}