Home > OS >  Android Jetpack Compose position children in LazyRow
Android Jetpack Compose position children in LazyRow

Time:06-20

I have a sequence of items I want to show as list of items in a Track. Only thing is, at the beginning, items have to be lined starting from middle of the track. Afterwards, the items can be scrolled normally.

e.g. at beginning :
MyTrack : [----blankSpace 50%-------[dynamic item1[[dynamic item2][dynamic item3]--]

after scrolling when all items are visible for example: MyTrack[[item1][item2][item3][item4][item5]]

This Row has to be scrollable and each item could have varying width.

This is the item on the track:

    data class MyItem(val widthFactor: Long, val color: Color)

Question : is there. a way to give start position of the items in the LazyRow ? Or is there a better Layout I should use in Jetpack Compose ? A layout like LazyRow() won't work because there is no way to tell to start lining up items from middle of it.

I can use something like Canvas and drawRect of items in it but then I need to implement the swipe and scroll features like in LazyRow.

Thanks in advance.

CodePudding user response:

Use this to get screen width

val configuration = LocalConfiguration.current
val screenWidth = configuration.screenWidthDp.dp

Source - enter image description here

  • Related