Есть ли способ плавно получить прокручиваемый процент? Если нет, то как я могу исправить свой случай, учитывая, что элементы не занимают общую ширину родителя:
Это то, что у меня есть до сих пор. Код адаптирован для сокрытия конфиденциальной информации, но это должно работать:
Код: Выделить всё
@OptIn(ExperimentalFoundationApi::class)
@Composable
private fun SnappingRowWithIndicator(items: List) {
val state = rememberLazyListState()
val firstVisibleItemIndex = state.firstVisibleItemIndex
val percent = (firstVisibleItemIndex / (items.size).toFloat()) * 100f
LaunchedEffect(percent) {
val scrollText = "scroll: $percent"
println(scrollText)
}
LazyRow(
horizontalArrangement = Arrangement.spacedBy(16.dp),
state = state,
flingBehavior = rememberSnapFlingBehavior(lazyListState = state)
) {
items(items) { dto ->
Text(
modifier = Modifier
.height(32.dp)
.fillParentMaxWidth(0.9f)
.background(Color.White)
.padding(vertical = 8.dp),
color = Color.Black,
text = dto.toString(),
textAlign = TextAlign.Center
)
}
}
Row(
modifier = Modifier
.fillMaxWidth()
.padding(top = 8.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(8.dp, alignment = Alignment.CenterHorizontally)
) {
items.forEachIndexed { index, _ ->
// todo color and not color the dots according to the index and the percentage scrolled
Box(modifier = Modifier
.size(8.dp)
.background(color = DesignSystem.Color.white, shape = CircleShape))
}
}
}
[img]https://i. sstatic.net/MxifnTpB.png[/img]
Подробнее здесь: https://stackoverflow.com/questions/785 ... percentage