I'm trying to build a simple screen, but I'd want ...
# compose
z
I'm trying to build a simple screen, but I'd want to restrict the
width
of a
Column
to a percentage of the screen width. So I'm using
Modifier.fillMaxWidth(0.8f)
but the
Column
is still occupying the max screen width. Is this an expected behaviour and I haven't fully understood the
fraction
argument or it's some kind of a bug? I'm using
beta03
If that matters, the
Column
is put inside a
Surface
with
fillMaxSize()
set.
Copy code
Column(
        modifier = Modifier
            .fillMaxWidth(0.8f)
            .fillMaxHeight()
            .background(Color.Green)
    ) {
        val (email, setEmail) = remember { mutableStateOf(TextFieldValue()) }
        TextField(
            value = email,
            onValueChange = { setEmail(it) },
            modifier = Modifier
                .align(CenterHorizontally)
        )
    }
a
Surface
always propagates min size constraints to its children. You are setting
fillMaxSize()
on the surface, so the min width, which is the screen width, is passed to the
Column
. If you want to use
Surface
outside, remove the
fillMaxSize()
modifier or wrap the
Column
in a
Box
.
z
Thanks! But then shouldn't the
Column
be 80% of the min width? Unless the incoming max width is Infinity... the docs say that the incoming max width is multiplied by the fraction.
a
Min size is mandatory.