if i want to draw a fixed size colored rectangle, with a logo inside. Should i use an image inside a box? surface ? other? i never know
o
OG
09/27/2021, 11:55 PM
I think it may depend on how you want this component to lay out compared to others at the same elevation or what you're trying to do.
In this case I think Surface with a background color is preferred over Box, since Surface will correctly set the appropriate content color. (For your inner Image)
Using modifier.background on Box or other composables doesn't set the corresponding content color.
š 2
m
myanmarking
09/28/2021, 8:17 AM
yeah. i may have to read about it. i noticed lots of components have content color. idk what is that and what it influences the views
z
Zach Klippenstein (he/him) [MOD]
09/28/2021, 2:16 PM
It probably doesn't matter unless your logo is a vector image, although even then if it's branding it probably is very particular about its color. I would start with the simplest thing and only go more complex if you actually need to:
Copy code
Image(logo, modifier = Modifier
.background(Color.Red)
.size(width, height)
// Allow the logo to set its own size and center in the box
.wrapContentSize()
)
m
myanmarking
09/28/2021, 2:17 PM
uhh that works? I dismissed it at first, i assumed if i specified size, the image would have that same size. Iām gonna try. Thanks!!
myanmarking
09/28/2021, 2:21 PM
well, that works ya. but then, how can i specify gravity for the image? The Container is a Square, and the logo is at the bottom