1

I've looked at Anko 0.8 - unresolved lparams reference, but I'm not using lparams in the outermost layout like in that link.

I get 'unresolved reference: lparams' in the following code (and no import suggestions in Android Studio). Any ideas as to what I've missed and/or overlooked?

class LoginActivityUi: AnkoComponent<LoginActivity> {

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

            textView{
                text = "ASDF"
            }.lparams{

            }
        }
    }

}

Here are my dependencies ($kotlin_version is 1.2.71, $anko_version is 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"
}
radthemad4
  • 165
  • 1
  • 9

1 Answers1

2

Okay, so... As you can see in this diff, as of Anko 0.10.6 the verticalLayout methods have been modified to take initializer lambdas that are of type LinearLayout.() -> Unit instead of the previous _LinearLayout.() -> Unit types. The underscored _LinearLayout class is the one that defines the lparams methods that you're looking for, which is why it has gone missing due to this change.

There's already an open issue for this breaking change here: https://github.com/Kotlin/anko/issues/673

In the meantime, you can either stick with 0.10.5, or you can use linearLayout with an explicit orientation as a workaround:

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

    textView {
        text = "ASDF"
    }.lparams {

    }
}
zsmb13
  • 85,752
  • 11
  • 221
  • 226
  • 1
    THANK YOU! I've been wondering what the heck is up with this for so many hours. I was comparing and contrasting a different project where lparams worked fine (the outermost layout there wasn't a verticaLayout) and I was wondering why the heck that was. – radthemad4 Sep 30 '18 at 07:43