gpt4 book ai didi

android - ConstraintLayout 不必要的错误

转载 作者:太空狗 更新时间:2023-10-29 13:48:02 28 4
gpt4 key购买 nike

我正在使用 ConstraintLayoutlayout 包裹dataBinding 的标签,所有布局在执行和运行时都运行良好,但我遇到了一个烦人的问题:

xml screenshot

如您所见,约束 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>

最佳答案

在编辑器中保留布局后,我可能已经为您找到了解决方案。此处可能的原因可能是 xmlns:bindxmlns: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>

关于android - ConstraintLayout 不必要的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51150965/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com