如何解决MotionLayout 和数据绑定
我在 MotionLayout 中有一个按钮:
<com.google.android.material.button.MaterialButton
android:id="@+id/button"
style="@style/MyButtonStyle"
android:layout_marginBottom="@{DEBUG ? 40dp : 16dp}"
android:paddingStart="34dp"
android:paddingEnd="34dp"
android:text="Next"
android:textAlignment="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
tools:enabled="false" />
和此按钮的 ConstraintSet:
<Constraint
android:id="@+id/button"
style="@style/MyButtonStyle"
android:layout_marginBottom="@{DEBUG ? 40dp : 16dp}"
android:paddingStart="34dp"
android:paddingEnd="34dp"
android:text="Next"
android:textAlignment="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
tools:enabled="false"
app:debugMarginBottom="@{@dimen/gap_40_dp}"
app:marginBottom="@{@dimen/gap_16_dp}"
>
而 app:debugMarginBottom
和 app:marginBottom
是我创建的 bindingAdapter 值。
问题是编译失败导致 app:debugMarginBottom 未知(但如果我把它放在布局本身,一切正常)。
如何在 MotionLayout 中使用数据绑定?
谢谢。
解决方法
一般来说,ConstraintSet/Constraint 不是 rec/layout 文件。它们不包含布局的所有标签。它们包含 ConstraintLayout 和 View Transforms 的标签。 在 MotionLayout 中使用时,它们还可以包含特殊的 motionLayout 相关标签。
有关约束中标签的详细信息,请参阅 link。
它们表面上很相似,所以我们不会有两个不同的词来表示同一件事。 (例如 margin_top)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。