我在ConstraintLayout
中使用layout
包裹着dataBinding
标记,所有布局在执行和运行时都可以正常运行,但是我遇到了一个令人讨厌的问题:
如您所见,约束ID的意思是“无法解析符号'@ + id / tvAccount'”,在尝试提交时似乎是错误,但是工作流或应用程序没有任何问题,并且一切正常。所有xml文件都相同。清理,使高速缓存无效等无法修复它。有人遇到过同样的问题吗?
编辑:
悬停的XML代码,当您将鼠标悬停在app:layout_constraintTop_toBottomOf="@+id/imageViewSplash"
上时,它会说“无法解析符号'@ + id / imageViewSplash'”:
<?xml version="1.0" encoding="utf-8"?>
<layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<!--suppress AndroidUnknownAttribute -->
<data class="SplashBinding"/>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.splash.SplashFragment">
<ImageView
android:id="@+id/imageViewSplash"
android:layout_width="wrap_content"
android:layout_height="39dp"
android:layout_marginBottom="8dp"
android:contentDescription="@string/content_description_splash_icon"
android:src="@mipmap/splash_icon"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<ImageView
android:id="@+id/imageViewSplashLoader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginTop="16dp"
android:contentDescription="@string/content_description_splash_loading"
android:src="@mipmap/splash_loader"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageViewSplash"/>
</android.support.constraint.ConstraintLayout>
</layout>
编辑2:
当您将鼠标悬停在app:layout_constraintTop_toBottomOf="@+id/imageViewSplash"
上时,即使没有<layout>
标签,也是同样的错误:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.splash.SplashFragment">
<ImageView
android:id="@+id/imageViewSplash"
android:layout_width="wrap_content"
android:layout_height="39dp"
android:layout_marginBottom="8dp"
android:contentDescription="@string/content_description_splash_icon"
android:src="@mipmap/splash_icon"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<ImageView
android:id="@+id/imageViewSplashLoader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginTop="16dp"
android:contentDescription="@string/content_description_splash_loading"
android:src="@mipmap/splash_loader"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageViewSplash"/>
</android.support.constraint.ConstraintLayout>
答案 0 :(得分:1)
在编辑器中保留布局后,我可能会为您找到解决方案。可能的原因可能是xmlns:bind
和xmlns:android
请尝试按照以下步骤操作,该操作不会向我显示任何错误。
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:bind="http://schemas.android.com/apk/res/android">
<data></data>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/tvAccount"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginTop="13dp"
android:layout_marginEnd="32dp"
android:text="Account"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tvPhoneValidationTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Phone Validation"
app:layout_constraintEnd_toEndOf="@id/tvAccount"
app:layout_constraintStart_toStartOf="@id/tvAccount"
app:layout_constraintTop_toBottomOf="@id/tvAccount" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
答案 1 :(得分:0)
我已经通过将app
命名空间从<layout/>
移到<ConstraintLayout/>
标签解决了相同的问题。
之前:
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<androidx.constraintlayout.widget.ConstraintLayout
...>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
之后:
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
...>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>