【问题标题】:Jetpack Compose - MotionLayoutJetpack Compose - MotionLayout
【发布时间】:2021-12-26 17:07:18
【问题描述】:

什么等价于:

<Transition
    motion:constraintSetEnd="@id/end"
    motion:constraintSetStart="@id/start"
    motion:duration="1500"
    motion:motionInterpolator="linear">
    <OnSwipe
        motion:dragDirection="dragUp"
        motion:touchAnchorId="@id/view1"
        motion:touchAnchorSide="top" />
</Transition>

关于 Compose 的 MotionLayout 吗? 我在这两个链接上都没有看到答案:

https://github.com/androidx/constraintlayout/wiki/Introduction-to-MotionLayout-in-Compose https://github.com/androidx/constraintlayout/wiki/Compose-MotionLayout-JSON-Syntax

我只想在手动滚动时为我的场景设置动画,而不是像示例中那样单击按钮。

谢谢!

【问题讨论】:

    标签: android android-constraintlayout android-jetpack-compose android-motionlayout


    【解决方案1】:

    Compose 中的 MotionLayout 还没有内置支持。

    Compose 具有滑动处理功能
    一种方法如下所示:

    var componentHeight by remember { mutableStateOf(1000f) }
    val swipeableState = rememberSwipeableState("Bottom")
    val anchors = mapOf(0f to "Bottom", componentHeight to "Top")
    val mprogress = (swipeableState.offset.value / componentHeight)
    

    然后将进度传递到 MotionLayout Composable。

      MotionLayout(motionScene = "",  progress = mprogress, ...)
    

    Here 是您如何编写代码的示例。

    【讨论】:

    • 太棒了!这正是我需要的!谢谢你。你知道是否可以在 MotionLayout 顶部添加 SwipeRefresh 吗?
    • 其他问题:你知道如何使用 JSON 语法制作一个垂直偏差吗?我没有找到参数。
    • 总结一下,有没有可以找到所有不同 json 值的链接?
    猜你喜欢
    • 2023-01-22
    • 2021-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-26
    • 2021-02-21
    • 2020-12-29
    相关资源
    最近更新 更多