I can't figure out how to keep my Button from gett...
# compose
d
I can't figure out how to keep my Button from getting pushed off the screen when the Text in the same Row is too long (even though it has TextOverflow.Ellipsis)... I have a Spacer with weight(1.F) between them to push the button to the End, it works when the text is short... (see thread for code and screen shot)
Copy code
Row(
        modifier = Modifier
            .padding(10.dp)
            .fillMaxWidth(),
    ) {
        Row {
            AsyncImage(
                model = item.imageUrl,
                contentDescription = null,
                modifier = Modifier.size(40.dp)
            )
            Column(
                modifier = Modifier.padding(start = 15.dp, end = 15.dp)
            ) {
                Text(
                    text = item.name,
                    maxLines = 1,
                    overflow = TextOverflow.Ellipsis,
//                    fontSize = 15.sp,
                    style = MaterialTheme.typography.bodyMedium
                )
                Text(
                    text = "When last updated",
                    style = MaterialTheme.typography.labelMedium,
                    color = MaterialTheme.colorScheme.tertiary
                )
            }
        }
        Spacer(Modifier.weight(1f))
        AppActionButton(onClick = { /*TODO*/ }) {
            Text(stringResource(id = buttonTextId), softWrap = false)
        }
    }
message has been deleted
r
Hmm, remove the
Spacer
and then in the 2nd row (empty one) set this:
Copy code
Row(modifier = Modifier.weight(1f)){
d
That works, thanks! Not that I understand what happened and what
weight
really means.
r
Hahaha no worries, I haven't used too much weight tbh but I was reading the docs from
weight
and it says that it measures the unweighted children and then for the weight ones it *distributes accordingly (To the available space and other weight siblings).* What I get is that Row wasn't distributed accordingly previously and was just pushing as much as it wanted. If you added
.weight(1f)
to it, then it was being distributed along side the
Spacer
and it was respecting the
Button
. So if you remove the
Spacer
now it's only the sibling
Row
filling the entire parent
Row
and respecting the
Button
. Also notice that
weight(1f)
has a
fill = true
by default, if you set it to false the
Button
won't be at the end, but next to the
Row
sibling TLDR: Unweighted ones have priority over weight ones! You can tell weight ones to fill the remaining available space or not
d
Thanks a lot, I think I'm finally starting to understand weight!