【问题标题】:Bidirectional Swipe using Swipeable Jetpack Compose使用 Swipeable Jetpack Compose 进行双向滑动
【发布时间】:2021-12-02 19:15:52
【问题描述】:

我在 jetpack compose 中使用 Swipeable 从左到右或从右到左滑动手势。但是我很困惑,如果我可以通过一个可滑动的方法来传递它们?

 Box(
            modifier = Modifier
                .fillMaxWidth()
                .swipeable(
                    state = swipeAbleState,
                    anchors = mapOf(0f to 0, sizePx to 1),
                    thresholds = { _, _ ->
                        FractionalThreshold(0.3f)
                    },
                    orientation = Orientation.Horizontal
                )

这将为我提供从左到右的滑动,同样,如果我在anchor 中传递mapOf(0f to 0, -sizePx to 1),它将为我提供从右到左的滑动,现在我需要将它们都放在我的Box 中是否可能?

【问题讨论】:

标签: android android-jetpack-compose


【解决方案1】:

尝试:anchors = mapOf(0f to 0, sizePx to 1, -sizePx to -1)

【讨论】:

  • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
【解决方案2】:

如果您想要左右两边,请使用以下锚点

    val anchors = mapOf(0f to 0, sizePx to 1, -sizePx to 2)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-07-07
    • 1970-01-01
    • 1970-01-01
    • 2022-12-19
    • 2022-01-22
    • 2023-02-03
    • 2022-11-22
    相关资源
    最近更新 更多