数据绑定不适用于约束布局组
Databinding not working with constraint layout Groups
我在布局 fragment_hurdle_otp.xml
文件中使用了组视图。
.
.
.
<android.support.constraint.Group
android:id="@+id/group_navigate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:constraint_referenced_ids="iv_navigate_option,tv_navigate_option" />
<ImageView
android:id="@+id/iv_navigate_option"
android:layout_width="@dimen/space_16"
android:layout_height="@dimen/space_16"
android:layout_marginStart="@dimen/default_space_24"
app:layout_constraintBottom_toBottomOf="@+id/tv_navigate_option"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/tv_navigate_option"
app:srcCompat="@drawable/outline_lock_vector" />
<TextView
android:id="@+id/tv_navigate_option"
style="@style/LoginButtonLight"
android:layout_width="wrap_content"
android:layout_height="@dimen/wh_40"
android:layout_marginTop="@dimen/default_space"
android:layout_marginBottom="@dimen/default_margin_8"
android:padding="@dimen/default_space_small"
android:text="@{vm.tvNavigateOption}"
app:layout_constraintBottom_toTopOf="@+id/tv_verify"
app:layout_constraintStart_toEndOf="@+id/iv_navigate_option"
android:background="@drawable/white_selectable_item_background"
android:onClick="@{()->vm.onNavigate()}"
tools:text="@string/login_with_password" />
.
.
.
但是在构建时,为此布局生成绑定文件失败并引发编译错误。
Class elements: (java.lang.String,java.lang.String)void init
/Users/.../../..application/build/generated/data_binding_base_class_source_out/developersProductionDebug/dataBindingGenBaseClassesDevelopersProductionDebug/out/com/phone/app/databinding/FragmentHurdleOtpBinding.java:27: error: cannot find symbol
public final Group groupNavigate;
如果我删除组视图,一切正常。
您已经将项目迁移到 AndroidX
。所以,你必须使用 AndroidX
库而不是 Support
。在您的项目中,不要将 Support
库与 AndroidX
.
混用
使用
androidx.constraintlayout.widget.Group
而不是
android.support.constraint.Group
还在模块级别 build.gradle
中包含 ConstraintLayout
的 AndroidX
库
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
我在布局 fragment_hurdle_otp.xml
文件中使用了组视图。
.
.
.
<android.support.constraint.Group
android:id="@+id/group_navigate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:constraint_referenced_ids="iv_navigate_option,tv_navigate_option" />
<ImageView
android:id="@+id/iv_navigate_option"
android:layout_width="@dimen/space_16"
android:layout_height="@dimen/space_16"
android:layout_marginStart="@dimen/default_space_24"
app:layout_constraintBottom_toBottomOf="@+id/tv_navigate_option"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/tv_navigate_option"
app:srcCompat="@drawable/outline_lock_vector" />
<TextView
android:id="@+id/tv_navigate_option"
style="@style/LoginButtonLight"
android:layout_width="wrap_content"
android:layout_height="@dimen/wh_40"
android:layout_marginTop="@dimen/default_space"
android:layout_marginBottom="@dimen/default_margin_8"
android:padding="@dimen/default_space_small"
android:text="@{vm.tvNavigateOption}"
app:layout_constraintBottom_toTopOf="@+id/tv_verify"
app:layout_constraintStart_toEndOf="@+id/iv_navigate_option"
android:background="@drawable/white_selectable_item_background"
android:onClick="@{()->vm.onNavigate()}"
tools:text="@string/login_with_password" />
.
.
.
但是在构建时,为此布局生成绑定文件失败并引发编译错误。
Class elements: (java.lang.String,java.lang.String)void init /Users/.../../..application/build/generated/data_binding_base_class_source_out/developersProductionDebug/dataBindingGenBaseClassesDevelopersProductionDebug/out/com/phone/app/databinding/FragmentHurdleOtpBinding.java:27: error: cannot find symbol public final Group groupNavigate;
如果我删除组视图,一切正常。
您已经将项目迁移到 AndroidX
。所以,你必须使用 AndroidX
库而不是 Support
。在您的项目中,不要将 Support
库与 AndroidX
.
使用
androidx.constraintlayout.widget.Group
而不是
android.support.constraint.Group
还在模块级别 build.gradle
ConstraintLayout
的 AndroidX
库
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'