android - MotionLayout 中的 ConstraintSets 没有复制粘贴属性

标签 android android-constraintlayout

我想将 MotionLayout 用于没有任何代码的动画,只需 XML。
当我制作 ConstraintSets 时,如果我使用所有约束属性(如 layout_widthlayout_constraintEnd_toEndOf 等),它工作正常,但我不更改它们。我可以使用仅在动画中真正改变的属性吗?
与此相关的另一个问题:我可以从任何状态进行转换吗?例如,我想用三个按钮管理三个案例。我可以在六个转换中做到这一点(每个状态到其他状态),但可能只做三个?

最佳答案

简短的回答是肯定的,主要是。
长答案...
在 MotionScene 中,CostraitnSets 是从布局“派生的”。
您也可以从另一个 ConstraintSet 派生。
您可以覆盖不同粒度级别的属性。
简单 :

<ConstraintSet>
<Constraint androdi:id="@+id/a 
  motion:top_margin="23dp"
  ...
  />
</ConstraintSet>
仅简单定义的约束标签覆盖布局
分段:
<ConstraintSet>
<Constraint androdi:id="@+id/a">
  <Layout motion:top_margin="23dp" ...\>
  <PropertySet android:alpha="0.3" ...\>
  <Transform android:scaleX="1.3" ...\>
  <Motion motion:transitionEasing="linear ...\>
 
  </ConstraintSet>
</ConstraintSet>
如果您有一个部分,则仅替换部分所有布局标签都被替换
约束覆盖:
<ConstraintSet>
<ConstraintOVerride androdi:id="@+id/a" 
      motion:top_margin="23dp" 
      android:alpha="0.3"...\>
 
  </ConstraintSet>
</ConstraintSet>
个别属性已更改,但您 不能使用“ anchor 属性”,例如
layout_constraintTop_ToTopOf
第二个问题
中等答案:你可以过渡任何国家
通常情况下,过渡是往返于
 <Transition
        motion:constraintSetEnd="@+id/end"
        motion:constraintSetStart="@id/start"
        motion:duration="6000">
        <OnClick motion:targetId="@+id/button1" />
您可以省略运动:constraintSetStart。
 <Transition
        motion:constraintSetEnd="@+id/end"
        motion:duration="6000">
        <OnClick motion:targetId="@+id/button1" />
这意味着点击时可以从任何状态进入此状态。即使在状态之间的转换!
你可以看到这样的代码 here

关于android - MotionLayout 中的 ConstraintSets 没有复制粘贴属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68441241/

相关文章:

Android:在 ConstraintLayout 中保持全宽和未定义高度 ImageView 的比例?

android-layout - 如何忽略子元素中的 ConstraintLayout 填充

android - 约束布局内的回收器 View 问题

android - 将最大 View 的左侧与约束布局对齐

Android - 使用 Joda Time 时无法使用 Proguard 导出 apk

javascript - 使用 HTML5 媒体捕获的 IOS Chrome 浏览器中的音频录制问题

android - 使用 github 操作和问题签署发布 apk

android - 在网格中添加 OxyPlot View

android - RelativeLayout params AddRule 是否始终有效?

android - 布局在某些设备上看起来很乱