【发布时间】:2018-12-11 13:18:49
【问题描述】:
我使用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>
【问题讨论】:
-
将您的 xml 布局分享为文本而不是图像谢谢
-
@NileshRathod 共享为文本不会在此处突出显示错误
-
@TimCastelijns 删除 + 后仍然存在
-
@MelihAksoy 你能分享你的布局代码吗
-
@MelihAksoy 删除约束并再次从“设计”选项卡中设置它。
标签: android android-xml android-constraintlayout