首页 > 解决方案 > Android studio 这里不允许使用元素 androidx.coordinatorlayout.widget.CoordinatorLayout

问题描述

我正在使用 android 数据绑定和 android studio。我有以下 xml 文件。

我正面临问题。

androidx.coordinatorlayout.widget.CoordinatorLayout此处不允许使用元素

我尝试使用 MaterialCardView 更改 CordinatorLayout 并再次显示

com.google.android.material.card.MaterialCardView此处不允许使用元素

我无法理解这里有什么问题。但是当我构建项目时,它构建成功。但 android studio 不显示自动完成。任何人有任何想法请。

<layout xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <data>

    </data>

    <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#AF5C5C"
        android:padding="25dp"
        tools:context=".LoginActivity">
        <com.google.android.material.card.MaterialCardView
            android:layout_width="match_parent"
            android:id="@+id/wrapper_card"
            app:cardCornerRadius="15dp"
            style="@style/Widget.MaterialComponents.CardView"
            android:elevation="10dp"
            android:layout_gravity="center_vertical"
            android:layout_height="wrap_content">
            <androidx.constraintlayout.widget.ConstraintLayout
                android:layout_width="match_parent"
                android:id="@+id/view"
                android:padding="10dp"
                android:layout_height="wrap_content">
                <androidx.appcompat.widget.AppCompatButton
                    app:layout_constraintTop_toTopOf="parent"
                    app:layout_constraintLeft_toLeftOf="parent"
                    app:layout_constraintRight_toLeftOf="@id/button_show_signup"
                    android:id="@+id/button_show_signin"
                    android:text="Signin"
                    style="@style/Widget.AppCompat.Button.Borderless.Colored"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />
                <androidx.appcompat.widget.AppCompatButton
                    app:layout_constraintTop_toTopOf="parent"
                    app:layout_constraintLeft_toRightOf="@id/button_show_signin"
                    app:layout_constraintRight_toRightOf="parent"
                    android:id="@+id/button_show_signup"
                    android:text="SignUP"
                    style="@style/Widget.AppCompat.Button.Borderless.Colored"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />
                <com.google.android.material.textfield.TextInputLayout
                    app:layout_constraintTop_toBottomOf="@id/button_show_signin"
                    android:hint="@string/user_name"
                    android:id="@+id/user_name_container"
                    style="@style/AppTextInputLayout"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">
                    <com.google.android.material.textfield.TextInputEditText
                        android:layout_width="match_parent"
                        style="@style/AppTextInputEditText"
                        android:id="@+id/user_edit_text"
                        android:layout_height="wrap_content" />
                </com.google.android.material.textfield.TextInputLayout>
                <com.google.android.material.textfield.TextInputLayout
                    app:layout_constraintTop_toBottomOf="@id/user_name_container"
                    android:hint="@string/mobile"
                    android:id="@+id/mobile_number_container"
                    style="@style/AppTextInputLayout"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">
                    <com.google.android.material.textfield.TextInputEditText
                        android:layout_width="match_parent"
                        android:id="@+id/mobile_number"
                        android:inputType="textPassword"
                        style="@style/AppTextInputEditText"
                        android:layout_height="wrap_content" />
                </com.google.android.material.textfield.TextInputLayout>

                <com.google.android.material.textfield.TextInputLayout
                    app:layout_constraintTop_toBottomOf="@id/mobile_number_container"
                    android:hint="@string/address"
                    android:id="@+id/password_container"
                    style="@style/AppTextInputLayout"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">
                    <com.google.android.material.textfield.TextInputEditText
                        android:layout_width="match_parent"
                        android:id="@+id/password_edit_text"
                        android:inputType="textPassword"
                        style="@style/AppTextInputEditText"
                        android:layout_height="wrap_content" />
                </com.google.android.material.textfield.TextInputLayout>



            </androidx.constraintlayout.widget.ConstraintLayout>
        </com.google.android.material.card.MaterialCardView>
        <androidx.appcompat.widget.AppCompatImageView
            android:layout_width="70dp"
            android:background="@drawable/circular_image"
            app:srcCompat="@drawable/ic_arrow_forward_black_24dp"
            android:padding="15dp"
            android:id="@+id/login_button"
            app:layout_anchor="@id/view"
            android:tint="#FFFFFF"
            app:layout_anchorGravity="bottom|center"
            android:elevation="10dp"
            android:layout_height="70dp"/>
    </androidx.coordinatorlayout.widget.CoordinatorLayout>
</layout>

标签: androidandroid-studio

解决方案


这个问题在我身上发生过几次,所以我希望这对你也有用:

选项 1:文件 > 使缓存无效并重新启动 > 使缓存无效并重新启动然后 gradle 同步您的项目(如果它打开,则禁用 gradle 离线模式)

选项 2:从您的项目中删除 .idea 文件夹关闭项目并重新打开以让 Android Studio 重新生成新的 .idea 同步您的项目


推荐阅读