android-jetpack-compose - 如何将某些东西拖到另一个视图后面
问题描述
我正在尝试编写类似于此博客文章中描述的自定义视图的日历,这也有点像 Excel 电子表格。顶部的标题和左侧的列计数。那些粘在顶部和左侧
https://danielrampelt.com/blog/jetpack-compose-custom-schedule-layout-part-1/
与这篇博客文章不同,它在内容上添加了水平/垂直滚动修饰符以保持标题不变,我需要能够向各个方向拖动我的内容。
看起来我需要使用 apointInput
和 a 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)) } )
)
}
如何启用向任何方向拖动,而不与其他视图重叠?我希望内容在进入标题时隐藏/消失在标题后面。
解决方案
只需将标题和内容的 z-index 设置为 5,将可拖动的 z-index 设置为较低的值。达到适当的位置后将自动剪裁
推荐阅读
- python - 尝试在 python Django 中运行 Runserver 时出现运行时错误
- php - 如何在 WHMCS 插件模块中设置附加属性
- selenium - AndroidDriver 等待时秒表计时器未更新
- json - 如何使用 cloudformation 复制 AMI
- python-3.x - Python3 使用 subprocess.run() 时如何将二进制数据传递给标准输入?
- python - ModuleNotFoundError:将简单应用程序(通过 pymongo 连接到 Atlas)部署到 Heroku 时,Flask 中没有名为“0”的模块
- groovy - 无法将具有类“java.lang.String”的对象转换为类“java.util.map”
- typescript - 访问我的 d.ts 文件中的导出模块
- php - HasOne 关系表单不更新模型
- c++ - VS Code 在尝试编译 C++ 代码时将我抛出到 settings.json