You need to enable JavaScript to run this app. 如何在MotionLayout中修改CircularProgressIndicator的自定义属性
优惠活动
大模型
产品
解决方案
定价
更多

如何在MotionLayout中修改CircularProgressIndicator的自定义属性

解决方案

CustomAttribute完全支持修改这两个自定义属性,你之前尝试失败大概率是属性名拼写错误或者依赖版本不匹配的问题,按下面的步骤调整即可:

  1. 先确认你的Material Components依赖版本在1.5.0及以上,低版本的CircularProgressIndicator没有公开对应的setter方法,无法通过CustomAttribute调用。
  2. 在MotionScene的两个状态对应的ConstraintSet中,给CircularProgressIndicator的约束节点添加如下配置:

展开状态的ConstraintSet示例

<Constraint
    android:id="@+id/your_circular_progress_id"
    ...>
    <CustomAttribute
        app:attributeName="indicatorSize"
        app:dimensionValue="85dp" />
    <CustomAttribute
        app:attributeName="trackThickness"
        app:dimensionValue="17dp" />
</Constraint>

折叠状态的ConstraintSet示例

<Constraint
    android:id="@+id/your_circular_progress_id"
    ...>
    <CustomAttribute
        app:attributeName="indicatorSize"
        app:dimensionValue="40dp" />
    <CustomAttribute
        app:attributeName="trackThickness"
        app:dimensionValue="5dp" />
</Constraint>

注意事项

  • attributeName的取值必须和View公开的setter方法去掉set前缀后的名称完全一致,首字母小写,严格遵循驼峰命名,拼写错误会导致属性不生效。
  • 所有View的public setter方法对应的属性都可以通过CustomAttribute动态修改,不存在只能用预定义属性的限制。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.21 15:54:04