Quantcast
Channel: Active questions tagged row - Stack Overflow
Viewing all articles
Browse latest Browse all 445

FlowRow make elements in row stretch to available width

$
0
0

In Jetpack Compose FlowRow, how can I make the elements within the rows stretch the full width of the screen.

If this code is run on a Pixel 8, the first 4 names are on one row which is what I want, but there is white space after the last name (Peter). I basically want the view to dynamically add even spacing around all 4 pieces of text so that the full view width is used.

The 1st image shows what the code is currently doing. The 2nd image shows what I want the code to do (I have manually created this view by specifying the padding for each element in nameOptions), but want a way for it to be done automatically based on the available width

[Before1After

@OptIn(ExperimentalLayoutApi::class)@Composablefun Names() {    var nameOptions = arrayOf("Luke", "Christopher", "Samuel", "Peter", "Johnathan", "James", "Aydan", "Matthew", "Andrew")    Column (        modifier = Modifier.padding(10.dp)    ) {        Spacer(modifier = Modifier.height(50.dp))        FlowRow(            horizontalArrangement = Arrangement.spacedBy(10.dp),            verticalArrangement = Arrangement.spacedBy(10.dp),        ) {            for (name in nameOptions) {                Text(                    text = name,                    softWrap = false,                    modifier = Modifier                        .border(                            width = 1.dp,                            color = Color.Black,                            shape = RoundedCornerShape(15.dp)                        )                        .padding(10.dp)                )            }        }    }}

Viewing all articles
Browse latest Browse all 445

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>