Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to stop Text overlapping the Icon when Text is longer in a Row

Hi apologies the title is not so clear.

I have a Row with a Text and Icon. Row has verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.SpaceBetween

If the text in the row is longer the Icon is not visible.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

how can I resolve this please

    Row(
        modifier = modifier.fillMaxWidth(),
        verticalAlignment = Alignment.CenterVertically,
        horizontalArrangement = Arrangement.SpaceBetween
) {
    Text(
            text = title,
            style = MaterialTheme.typography.bodyMedium,
            color = Color.White
    )
    Icon(
            modifier = Modifier
                    .size(24.dp),
            contentDescription = null,
            imageVector = icon,
            tint = MaterialTheme.colorScheme.primary,

    )
}

This is a preview if text is small and text is longer where the arrow is not visible.

How can I ensure Icon is visible when the text is long please

Thanks
R

enter image description here

>Solution :

You can try to use the weight Modifier:

Text(
    modifier = Modifier.weight(1f),
    text = title,
    style = MaterialTheme.typography.bodyMedium,
    color = Color.White
)

You then can remove the horizontalArrangement Modifier from your Row.

Composables with the weight Modifier will be measured after all sibling Composables without that Modifier. The remaining space is then distributed between the Composables with the weight Modifier. If only one Composable has the weight Modifier, all remaining space will be filled by that Composable.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading