https://kotlinlang.org logo
#android
Title
# android
y

Yuniel

11/29/2023, 11:15 AM
I want something like this:
🧵 2
c

Ciaran Sloan

11/29/2023, 11:50 AM
I would remove the last item from the list and not place it in the Lazy Row. Seeing as it doesnt need to be part of that row. Something like this:
Copy code
val stickyItem = allItems.last
            val scrollingItems = allItems.take(allItems.count() - 1)
            Row(modifier = Modifier.fillMaxWidth()) {
                LazyRow(modifier = Modifier.weight(1F)) {
                    items(scrollingItems) { item ->
                        RowItem(text = item)
                    }
                }
                RowItem(text = stickyItem)
            }
☝️ 1
y

Yuniel

11/29/2023, 11:54 AM
Thanks. With a row it doesn’t work as I spect but if the container is a box it works well
c

Ciaran Sloan

11/29/2023, 11:56 AM
can you elaborate more on what you mean by "it doesnt work" ? Im not using a box just a text and its working fine:
Copy code
val allItems = (1..20)
            val stickyItem = allItems.last
            val scrollingItems = allItems.take(allItems.count() - 1)
            Row(modifier = Modifier.fillMaxWidth()) {
                LazyRow(modifier = Modifier.weight(1F)) {
                    items(scrollingItems) { item ->
                        Text(text = "Item $item")
                    }
                }
                Text(text = "Item $stickyItem")
            }
y

Yuniel

11/29/2023, 2:01 PM
Sorry, I didn't understand you well before. I've now tested the code, and it works fine. It was failing earlier because I was dynamically creating the Button Icons and had set the padding, etc., incorrectly. Thank you very much for the response.
🙌🏼 1
c

Ciaran Sloan

11/29/2023, 2:18 PM
awesome, glad to have helped!
2 Views