https://kotlinlang.org logo
#compose
Title
# compose
s

Sheroz Nazhmudinov

04/03/2020, 7:45 PM
hey i’ve been playing with compose recently, and have a short question. I want to render the vector asset inside the row. Currently i’m doing smth like this:
Copy code
Row(modifier = Modifier.fillMaxHeight() + Modifier.fillMaxWidth()) {
    if (stateChecked.value) {
        VectorPainter(asset = vectorResource(id = R.drawable.ic_checkbox_on))
    } else {
        VectorPainter(asset = vectorResource(id = R.drawable.ic_checkbox_off))
    }
}
However, it doesn’t show anything on the screen. Is that approach correct, at all?
k

kartoffelsup

04/03/2020, 7:48 PM
Not sure if this is correct, but I'm using Icon:
Copy code
Icon(asset = VectorResource(R.drawable.ic_outline_menu_24))
as suggested in this thread: https://kotlinlang.slack.com/archives/CJLTWPH7S/p1584849322105100
s

Sheroz Nazhmudinov

04/03/2020, 7:50 PM
Thanks, it works 👍 I thought maybe i had some issue with my modifier.
a

Adam Powell

04/03/2020, 7:59 PM
you can write
Copy code
Modifier.fillMaxHeight() + Modifier.fillMaxWidth()
as
Copy code
Modifier.fillMaxHeight()
    .fillMaxWidth()
now 🙂
🔝 1
(or even just
Modifier.fillMaxSize()
)
s

Sheroz Nazhmudinov

04/03/2020, 8:00 PM
nice 👏 thank you!
s

Socheat KHAUV

04/07/2020, 9:22 AM
do you know how to resize the vector icon more bigger ?
Copy code
Box(gravity = ContentGravity.Center, modifier = Modifier.fillMaxSize()) {
    Icon(asset = vectorResource(R.drawable.ic_favorite))
}
k

kartoffelsup

04/07/2020, 8:25 PM
You can apply this modifier to your Icon:
Copy code
Modifier.preferredSize(60.dp, 60.dp)