【发布时间】:2021-06-30 01:26:35
【问题描述】:
我正在尝试编写一个类似于此博客文章中描述的自定义视图的日历,它也有点像 Excel 电子表格。顶部的标题和左侧的列计数。那些粘在顶部和左侧
https://danielrampelt.com/blog/jetpack-compose-custom-schedule-layout-part-1/
与这篇博文不同,它在内容上添加了水平/垂直滚动修饰符以保持标题不变,我需要能够向各个方向拖动我的内容。
看起来我需要使用pointInput 和detectDragGestures,但是当我使用它时,它会像我想要的那样拖动,标题固定在顶部并向左/向右移动,并且列数被固定向左并上下移动
但是当我向上或向左拖动时,日程内容会滚动到列/标题上。
我需要将拖动的内容放在标题/列指示器的后面。
我的布局是这样的
var offsetX by remember { mutableStateOf(0f) }
var offsetY by remember { mutableStateOf(0f) }
Column(
modifier = modifier.pointerInput(Unit) {
detectDragGestures { change, dragAmount ->
change.consumeAllChanges()
offsetX = (offsetX + dragAmount.x).coerceIn((-1 * unitWidth.toPx() * unitList.count()), 0f)
offsetY = (offsetY + dragAmount.y).coerceIn(-1 * hourHeight.toPx() * 24, 0f)
}
}
) {
Header(modifier = Modifier.offset { IntOffset(offsetX.roundToInt(), 0) } )
Row(modifier = Modifier.weight(1f)) {
SideBar( modifier = Modifier.offset { IntOffset(0, offsetY.roundToInt())})
Schedule( modifier = Modifier.offset { IntOffset(offsetX.roundToInt() + unitWidth.roundToPx(), offsetY.roundToInt()) }.weight(1f)) } )
)
}
如何启用向任意方向拖动,而不与其他视图重叠?我希望内容在进入标题时隐藏/消失在标题后面。
【问题讨论】: