Android Studio在logcat上出错已经为元素“android. support. v7. widget. CardView”指定了属性“xmlns:card_view”

rvpgvaaj  于 2022-11-27  发布在  Android
关注(0)|答案(2)|浏览(98)

当我尝试构建和运行应用程序时,LogCat出现以下错误。在我的应用程序中,我使用Cardview显示edittext和textview。当我尝试运行应用程序时,它显示以下错误:

Attribute "xmlns:card_view" was already specified for element "android.support.v7.widget.CardView".

它只显示此信息,甚至不显示问题的确切位置。
下面是包含CardView的XML:
活动基本信息:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v7.widget.Toolbar
            android:layout_width="match_parent"
            android:layout_height="@dimen/_46sdp">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <ImageView
                    android:layout_width="@dimen/_30sdp"
                    android:layout_height="@dimen/_30sdp"
                    android:layout_marginTop="@dimen/_8sdp"
                    android:src="@drawable/ic_arrow_back_black_24dp"/>



                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textColor="@android:color/white"
                    android:textStyle="bold"
                    android:layout_centerInParent="true"
                    android:textSize="@dimen/_16sdp"
                    android:text="@string/basic_info_header"/>

            </RelativeLayout>


        </android.support.v7.widget.Toolbar>

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.widget.NestedScrollView
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:layout_width="match_parent"
        android:background="@android:color/white"
        android:layout_height="match_parent">


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/white"
            android:orientation="vertical">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@android:color/white"
                android:orientation="horizontal">

                <ImageView
                    android:layout_width="@dimen/_25sdp"
                    android:layout_height="@dimen/_25sdp"
                    android:layout_marginTop="@dimen/_30sdp"
                    android:src="@drawable/contact_info"
                    android:layout_marginStart="@dimen/_40sdp"/>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginHorizontal="@dimen/_8sdp"
                    android:layout_marginTop="@dimen/_34sdp"
                    android:text="@string/contact_info_text"
                    android:textStyle="bold"
                    android:textColor="@color/textColor"
                    android:textSize="@dimen/_12sdp"/>
            </LinearLayout>



            <android.support.v7.widget.CardView

                android:id="@+id/cardView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="@dimen/_25sdp"
                android:layout_marginEnd="@dimen/_25sdp"
                android:layout_marginTop="@dimen/_25sdp"
                app:cardCornerRadius="@dimen/_10sdp"
                app:cardElevation="@dimen/_10sdp">

                <LinearLayout

                    android:background="@drawable/bg_layout"
                    android:layout_width="match_parent"
                    android:paddingBottom="@dimen/_2sdp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:orientation="vertical">


                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">

                    <TextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:paddingBottom="@dimen/_15sdp"
                        android:paddingTop="@dimen/_15sdp"
                        android:paddingEnd="@dimen/_10sdp"
                        android:gravity="end"
                        android:textColor="@android:color/white"
                        android:background="@color/colorPrimary"
                        android:text="Name"/>

                        <EditText
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="2"
                            android:paddingTop="@dimen/_15sdp"
                            android:paddingStart="@dimen/_10sdp"
                            android:paddingBottom="@dimen/_15sdp"
                            android:background="@android:color/transparent"
                            android:hint="First and Last name"
                            android:textSize="@dimen/_10sdp"/>

                    </LinearLayout>
                    <View
                        android:layout_width="match_parent"
                        android:layout_height="1dp"
                        android:background="#e2e2e2" />


                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">

                        <TextView
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:paddingBottom="@dimen/_15sdp"
                            android:paddingTop="@dimen/_15sdp"
                            android:paddingEnd="@dimen/_10sdp"
                            android:gravity="end"
                            android:textColor="@android:color/white"
                            android:background="@color/colorPrimary"
                            android:text="Email"/>

                        <EditText
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="2"
                            android:paddingTop="@dimen/_15sdp"
                            android:paddingStart="@dimen/_10sdp"
                            android:paddingBottom="@dimen/_15sdp"
                            android:background="@android:color/transparent"
                            android:hint="Email Address"
                            android:textSize="@dimen/_10sdp"/>

                    </LinearLayout>

                    <View
                        android:layout_width="match_parent"
                        android:layout_height="1dp"
                        android:background="#e2e2e2" />

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">

                        <TextView
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:paddingBottom="@dimen/_15sdp"
                            android:paddingTop="@dimen/_15sdp"
                            android:paddingEnd="@dimen/_10sdp"
                            android:gravity="end"
                            android:textColor="@android:color/white"
                            android:background="@color/colorPrimary"
                            android:text="Phone"/>

                        <EditText
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="2"
                            android:paddingTop="@dimen/_15sdp"
                            android:paddingStart="@dimen/_10sdp"
                            android:paddingBottom="@dimen/_15sdp"
                            android:background="@android:color/transparent"
                            android:hint="Phone Number"
                            android:textSize="@dimen/_10sdp"/>

                    </LinearLayout>

                </LinearLayout>

            </android.support.v7.widget.CardView>

            <View
                android:layout_width="match_parent"
                android:layout_height="@dimen/_1sdp"
                android:layout_marginTop="@dimen/_20sdp"
                android:layout_marginStart="@dimen/_20sdp"
                android:layout_marginEnd="@dimen/_20sdp"
                android:background="#bababa"/>

        </LinearLayout>

    </android.support.v4.widget.NestedScrollView>

</android.support.design.widget.CoordinatorLayout>

我的身材。

apply plugin: 'com.android.application'

android {
    dataBinding
            {
                enabled = true
            }

    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.newproject"
        minSdkVersion 22
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    //noinspection GradleCompatible
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:support-vector-drawable:28.0.0'
    //noinspection GradleDependency
    implementation 'com.android.support:support-v4:28.0.0-alpha1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    //rest services
    implementation 'com.squareup.retrofit2:adapter-rxjava2:2.5.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
    implementation 'com.squareup.retrofit2:converter-scalars:2.5.0'
    //design
    implementation 'com.android.support:cardview-v7:28.0.0'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    //image binding
    implementation 'com.squareup.picasso:picasso:2.71828'
    //design libraries
    implementation 'com.android.support:design:28.0.0'
    //reactive programming
    implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
    implementation 'io.reactivex.rxjava2:rxjava:2.1.12'
    //data binding
    implementation 'android.arch.lifecycle:extensions:1.1.1'
    implementation 'android.arch.lifecycle:livedata:1.1.1'
    annotationProcessor 'android.arch.lifecycle:compiler:1.1.1'
    implementation 'android.arch.lifecycle:viewmodel:1.1.1'
    //sdp library
    implementation 'com.intuit.sdp:sdp-android:1.0.3'
    implementation 'com.android.support:design:28.0.0'
    //circle image Viewer
    implementation 'de.hdodenhof:circleimageview:3.0.0'

}

我已经试过了:

  • 清理项目
  • 重建项目
  • 使缓存无效并重新启动android studio。

但一切都没有结果。

rslzwgfq

rslzwgfq1#

我遇到了一个类似的问题。为了解决这个问题,我只是删除了xml文件全局布局的layout_width和layout_height。

bz4sfanl

bz4sfanl2#

这意味着标记已在父级中定义,您将在子级中再次使用该标记

相关问题