Hi,
I am playing with anko for a few days and like it pretty much so far. Created some custom views which also went quite well.
The question I have is when to use lparams at which place? I understand that at top level elements you should do something like:
verticalLayout {
lparams(...) { ... }
}
But sometimes you should / can use:
verticalLayout {
editText {
lparams(...) {...} // <---- seems to work sometimes as well
}.lparams(...) {...} // <---- is this preferred / different from within editText{} ?
}
What is the difference between these two approaches? I can provide an example where it is actually working differently / not applying the lparams if required.
Thanks for the info already.
You should always write
verticalLayout {
// code
}.lparams { ... }
The other ways may be bug-prone. For example, by writing this:
verticalLayout {
lparams { ... }
}
you actually say "I want to put the newly created verticalLayout into another LinearLayout". If you put it to some other layout, you'll get a runtime exception.
Alright, thanks for the heads up.
Most helpful comment
You should always write
The other ways may be bug-prone. For example, by writing this:
you actually say "I want to put the newly created
verticalLayoutinto anotherLinearLayout". If you put it to some other layout, you'll get a runtime exception.