首页 > 解决方案 > 如何将某些东西拖到另一个视图后面

问题描述

我正在尝试编写类似于此博客文章中描述的自定义视图的日历,这也有点像 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)) } )
      )
 }
 

如何启用向任何方向拖动,而不与其他视图重叠?我希望内容在进入标题时隐藏/消失在标题后面。

标签: android-jetpack-compose

解决方案


只需将标题和内容的 z-index 设置为 5,将可拖动的 z-index 设置为较低的值。达到适当的位置后将自动剪裁


推荐阅读