捕捉指数lazyrow
我在Lazyrow的帮助下制作日历。我现在有一个问题,我希望该行在一定的滚动量后捕捉到索引,以便在索引之间不可能粘在索引中。有办法做到吗?
LazyRow(state = calendarViewModel.listState, modifier = Modifier.fillMaxWidth()) {
calendarYears.forEach {
items(it.months.count()) { index ->
calendarViewModel.onEvent(CalendarEvent.ClickedMenuItem(index))
CalendarRowItem(
modifier = Modifier.fillParentMaxWidth(),
calendarSize = it.months[index].amountOfDays,
initWeekday = it.months[index].startDayOfMonth.ordinal,
textColor = MaterialTheme.colors.secondaryVariant,
clickedColor = MaterialTheme.colors.primary,
textStyle = MaterialTheme.typography.body1
)
}
}
}
I am making a calendar with the help of a lazyRow. I now have the problem that I want the row to snap to the index after a certain scroll amount so it shouldn't be possible to be stuck in between indexes. Is there a way to do that?
LazyRow(state = calendarViewModel.listState, modifier = Modifier.fillMaxWidth()) {
calendarYears.forEach {
items(it.months.count()) { index ->
calendarViewModel.onEvent(CalendarEvent.ClickedMenuItem(index))
CalendarRowItem(
modifier = Modifier.fillParentMaxWidth(),
calendarSize = it.months[index].amountOfDays,
initWeekday = it.months[index].startDayOfMonth.ordinal,
textColor = MaterialTheme.colors.secondaryVariant,
clickedColor = MaterialTheme.colors.primary,
textStyle = MaterialTheme.typography.body1
)
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
首先要组合
您可以使用 将项目捕捉到给定位置:1.3.0
Starting with compose
1.3.0
you can use theFlingBehavior
that performs snapping of items to a given position:您可以从 canceranist Libraral 提供提供提供的提供的提供的提供的提供的提供的提供者这种爆炸行为在框外,并在内部使用
lazyrow
。可以使用 snapper库创建的另一个选项。 /users/474997/chris-banes“>@chris-banes
在
build.gradle.gradle
中添加依赖关系。并在您的
lazyrow
中使用它。结果:
You can use the
HorizontalPager
from accompanist library which provides this fling behavior out-of-the-box and it usesLazyRow
internally.Another option could be use the Snapper library created by @chris-banes
Add the dependency in your
build.gradle
.and use it in your
LazyRow
.Result:
在Gabriele的答案之上构建,以基于第一个可见项目(侧扣至开始)来捕捉,我们需要执行以下操作:
Building on top of Gabriele's answer, for snapping based on first visible item (side snapping to the start) we need to do the following: