Hi guys, do you know how to use properly cardView....
# anko
m
Hi guys, do you know how to use properly cardView. I am trying something like this:
Copy code
cardView(){
    lparams(height = wrapContent, width = matchParent){

    }
}
And it looks like there is no lparams here. But if I do something like
Copy code
verticalLayout(){
    cardView(){
        lparams(height = wrapContent, width = matchParent){

        }
    }

}
it is there. So it looks like I can’t use cardView like root view?
m
it looks like there is no lparams here
What do you mean? No such method? That’s because
lparams
methods are declared inside
_LinearLayout
,
_RelativeLayout
,
_FrameLayout
and so on. You can’t use
lparams
on any root view, try using explicit
layoutParams = SomeLayout.LayoutParams(...)
.
m
How you mean I can’t use lparams on any root view? I can use it with linearLayout(). So, why can’t I do the same with cardView ?
Oh, I understand now. There is no defined lparams method for cardView, but I can use layoutParams explicitly
Thanks. 👍
b
It’s because the lparams is in reference to the a view’s parent view. If there is no parent view, you can’t use lparams for any view. However, you can specifically set layoutParams, as you mentioned. If CardView were inside another viewgroup, you could use lparams.