You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Jetpack Compose MotionLayout XML属性等效实现及Json参数列表查询

Jetpack Compose MotionLayout 相关问题解答

XML属性对应效果实现

你给出的两个XML属性的对应实现方式如下:
首先你给出的第二个XML属性存在拼写误差,正确属性应为motion:layout_constraintVertical_bias="1.0",作用是设置组件在垂直约束区间的偏移比例,1.0代表完全对齐底部约束;motion:layout_constrainedHeight="true"的作用是限制组件高度不会超过上下约束的边界,即使内容高度超出约束范围也会被裁剪。

1. ConstraintSet DSL 实现

在constrain代码块中直接设置对应属性即可,示例代码:

val motionConstraintSet = ConstraintSet {
    val targetComponent = createRefFor("target")
    constrain(targetComponent) {
        // 绑定上下约束
        top.linkTo(parent.top)
        bottom.linkTo(parent.bottom)
        // 对应 motion:layout_constrainedHeight="true"
        constrainedHeight = true
        height = Dimension.wrapContent
        // 对应 motion:layout_constraintVertical_bias=1.0
        verticalBias = 1f
    }
}

2. JSON 格式 ConstraintSet 实现

JSON参数命名和原生XML属性完全一致,示例如下:

{
  "target": {
    "layout_constrainedHeight": true,
    "layout_constraintVertical_bias": 1,
    "topToTop": "parent",
    "bottomToBottom": "parent",
    "height": "wrap"
  }
}

JSON参数完整列表说明

目前官方没有对外发布单独的MotionLayout JSON参数完整列表,你可以直接对照Compose ConstraintSet DSL的参数命名,将驼峰命名转换为下划线格式、添加layout_前缀即可对应到JSON参数,几乎所有参数都和View体系MotionLayout的XML属性命名一致,可以直接对照使用。

内容的提问来源于stack exchange,提问作者Tonio

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.26 08:45:00