如何强制组成‘LazyColumn’像传统的可滚动元素,如RecyclerView或ListView?
当想用鼠标滚动时很有用,例如用vysor。
发布于 2022-04-26 11:03:27
解决方案是在修饰符中添加筛选器。
const val VERTICAL_SCROLL_MULTIPLIER = -4
// Helps with scrolling with mouse wheel (just like recycler view/list view without compose)
@ExperimentalComposeUiApi
@Composable
fun MyLazyColumn(
modifier: Modifier = Modifier,
state: LazyListState, // rememberLazyListState()
content: LazyListScope.() -> Unit
) {
LazyColumn(
state = state,
modifier = modifier
.pointerInteropFilter {
if (it.action == MotionEvent.ACTION_SCROLL) {
state.dispatchRawDelta(it.getAxisValue(MotionEvent.AXIS_VSCROLL) * VERTICAL_SCROLL_MULTIPLIER)
}
false
},
content = content
)
}https://stackoverflow.com/questions/71337795
复制相似问题