0

I've a button inside a 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" />

and a ConstraintSet for this button:

<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}"
           >

while app:debugMarginBottom and app:marginBottom are bindingAdapter values I created.

The problem is that the compilation fails cause app:debugMarginBottom is unknown (but if i put it in the layout itself, everything works).

How can I use data binding with MotionLayout?

Thanks.

Sharas
  • 1,985
  • 3
  • 20
  • 43
  • You have to declare [custom attributes](https://developer.android.com/training/constraint-layout/motionlayout#custom_attributes) as children of your `Constraint`. – Pawel Mar 17 '21 at 16:23
  • @Pawel doesn't work for me, do you have an example, to make sure i'm doing it right? – Sharas Mar 17 '21 at 16:29
  • sorry that was only a tip for constraintset complaining about unknown attributes, but I'm pretty sure databinding won't hook into MotionScene properly. – Pawel Mar 17 '21 at 16:43
  • DataBinding is a function of Layout. Constraint only contains ConstraintSet (It is not a layout) So.. style, android:paddingStart, android:paddingEnd, android:text, android:textAlignment, tools:enabled, app:debugMarginBottom. Are not attributes of Constraint – hoford Mar 17 '21 at 22:11

1 Answers1

0

In General ConstraintSet / Constraint are not rec/layout files. They do not contain all the tags of layout. They contain tags for ConstraintLayout and View Transforms. When used in MotionLayout They also can contain special motionLayout related tags.

For details on tags in Constraint see link.

They are superficially similar so that we do not have two different words for the same thing. (e.g. margin_top)

hoford
  • 4,918
  • 2
  • 19
  • 19