【问题标题】:android.support.v7.widget.CardView could not be found Android Studio [duplicate]找不到android.support.v7.widget.CardView Android Studio [重复]
【发布时间】:2019-11-12 13:28:19
【问题描述】:

我正在关注 Android 应用的本教程: https://www.youtube.com/watch?v=wW-AAXOy4u4

我添加了一个可能包含一些项目的列表;对于每个项目,我希望它是一张卡片。创建卡片,在 build.gradle 中导入依赖:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.core:core-ktx:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.squareup:android-times-square:1.6.5@aar'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
    implementation 'com.google.android.material:material:1.2.0-alpha01'
    implementation 'androidx.cardview:cardview:1.0.0'

}

这里建议: android.support.v7.widget.CardView could not be found (Android Studio 1.1 Preview)

尽管如此,我仍然收到“找不到 android.support.v7.widget.CardView”错误。

我得到的错误:

 The following classes could not be found:
    - android.support.v7.widget.CardView (Fix Build Path, Edit XML, Create 
    Class)
    Tip: Try to build the project.   Tip: Try to refresh the layout.

这是我的 main_activity_single_item 代码:​​

<android.support.v7.widget.CardView
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="@color/colorAccent"
android:elevation="4dp"
xmlns:android="http://schemas.android.com/apk/res/android">




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

        <ImageView
            android:layout_width="80dp"
            android:layout_height="105dp"
            android:id="@+id/ivMain"
            android:layout_marginStart="10dp"
            android:layout_marginLeft="10dp"
            />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/tvMain"
                android:textStyle="bold"
                android:layout_toRightOf="@+id/ivMain"
                android:layout_marginLeft="6dp"
                android:layout_toEndOf="@+id/ivMain"
                android:text="Timetable"
                android:textSize="24sp"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/tvDescription"
                android:layout_below="@+id/tvMain"
                android:layout_toRightOf="@+id/ivMain"
                android:layout_marginLeft="6dp"
                android:text="Description"
                android:textSize="16dp"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/tvClick"
                android:textSize="12dp"
                android:text="click here"
                android:layout_below="@+id/tvDescription"
                android:layout_alignBottom="@+id/ivMain"/>

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

我已经尝试过的: 改变了 res->value->styles from <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> to <style name="AppTheme" parent="Base.Theme.AppCompat.Light.NoActionBar"> (错误)

   File .. Invalidate caches / restart
    Build project

我在 Android Studio 上工作,我的 API 版本是 22

能否请您分享您对这个问题的见解?

如果您需要一些额外的信息,请告诉我。 非常感谢。

【问题讨论】:

  • 您必须使用 androidx 依赖项。 developer.android.com/jetpack/androidx/releases/cardview
  • androidx.cardview.widget.CardView
  • 问题是因为您在使用支持 v7 时在项目中添加了 androidx 支持。这是支持 v7 卡片视图。 android.support.v7.widget.CardView 使用这个。 androidx.cardview.widget.CardViewa

标签: android android-studio kotlin


【解决方案1】:

任意使用

androidx.cardview.widget.CardView

com.google.android.material.card.MaterialCardView

而不是

android.support.v7.widget.CardView

【讨论】:

  • @Lea,你得到答案了吗?告诉我
  • 是的,Asaduzzaman 博士,我得到了答复,非常感谢!我在您建议的第一个解决方案之前尝试过:androidx.cardview.widget.CardView 但之后我遇到了其他错误('未绑定......'类似的东西)。我没有尝试您的第二个解决方案。对我有用的是此链接的答案:stackoverflow.com/questions/53089633/…;我以为我对上一个答案留下了回复,但我今天没有找到它!非常感谢您的回答,Md.Asaduzzaman,并感谢您检查我是否找到了解决方案。最好的问候。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-12-29
  • 1970-01-01
  • 2020-02-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多