android - How to align two texts, one on the left margin and one on the right margin in Jetpack Compose? - Stack Overflow

I have two texts and I want the first one to be placed at the beginning of the left margin and the othe

I have two texts and I want the first one to be placed at the beginning of the left margin and the other one stuck to the right margin.

I'm trying this:

Row {
    Text(
        modifier = Modifier.weight(1f).padding(top = 16.dp, bottom = 8.dp),
        text = title,
        style = titleStyle,
        color = MaterialTheme.colorScheme.error
    )
    Text(
        modifier = Modifier.weight(1f).padding(top = 16.dp, bottom = 8.dp).fillMaxSize(),
        text = texts[1],
        color = MaterialTheme.colorScheme.error,
        style = style
    )
}

As you can see in the screenshot, the text on the right is not placed on the far right.

The desired result would be:

|LECTURA BREVE                   Ex 19, 4-6a| <- Right margin

How could I achieve this?

I have two texts and I want the first one to be placed at the beginning of the left margin and the other one stuck to the right margin.

I'm trying this:

Row {
    Text(
        modifier = Modifier.weight(1f).padding(top = 16.dp, bottom = 8.dp),
        text = title,
        style = titleStyle,
        color = MaterialTheme.colorScheme.error
    )
    Text(
        modifier = Modifier.weight(1f).padding(top = 16.dp, bottom = 8.dp).fillMaxSize(),
        text = texts[1],
        color = MaterialTheme.colorScheme.error,
        style = style
    )
}

As you can see in the screenshot, the text on the right is not placed on the far right.

The desired result would be:

|LECTURA BREVE                   Ex 19, 4-6a| <- Right margin

How could I achieve this?

Share Improve this question edited Mar 11 at 1:29 Edric 26.9k13 gold badges87 silver badges95 bronze badges asked Mar 10 at 12:04 A. CedanoA. Cedano 1,00117 silver badges50 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 5

Please try to use the horizontalArrangement attribute of the Row:

Row(
    modifier = Modifier.fillMaxWidth(),
    horizontalArrangement = Arrangement.SpaceBetween
) {
    Text(
        modifier = Modifier.padding(top = 16.dp, bottom = 8.dp),
        text = "Lectura Breve",
        color = MaterialTheme.colorScheme.error
    )
    Text(
        modifier = Modifier.padding(top = 16.dp, bottom = 8.dp),
        text = "Ex 19,4-6a",
        color = MaterialTheme.colorScheme.error,
    )
}

If you rather want to solve this using weights, then you should only assign the weight Modifier to the first Text Composable:

Row {
    Text(
        modifier = Modifier.padding(top = 16.dp, bottom = 8.dp).weight(1f),
        text = "Lectura Breve",
        color = MaterialTheme.colorScheme.error
    )
    Text(
        modifier = Modifier.padding(top = 16.dp, bottom = 8.dp),
        text = "Ex 19,4-6a",
        color = MaterialTheme.colorScheme.error,
    )
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744847816a4596949.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信