缺少类android.support.v7.widget.CardView

时间:2019-10-17 02:36:06

标签: android android-layout cardview gradle-dependencies

我已经从此tutoriel构建了文本识别应用,但是我的布局给我带来了一些问题

找不到以下类别:

  

android.support.v7.widget.CardView

Expectation result

Reality current result

我缺少什么或做错了什么?

build.gradle应用

implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'

activity_main

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:cardBackgroundColor="#fff"
            app:cardUseCompatPadding="true"
            app:cardCornerRadius="3dp"
            app:cardElevation="3dp">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:padding="5dp">
                <TextView
                    android:text="Result"
                    android:textColor="@color/colorPrimary"
                    android:textSize="20sp"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />
                <EditText
                    android:id="@+id/resultET"
                    android:hint=""
                    android:autoLink="all"
                    android:padding="5dp"
                    android:background="@null"
                    android:textColor="#000"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:autofillHints=""/>
            </LinearLayout>
      </android.support.v7.widget.CardView>
   </LinearLayout>
 </ScrollView>
</RelativeLayout>

3 个答案:

答案 0 :(得分:0)

如果您是在androidx replace下进行项目

implementation 'android.support.v7.widget.CardView'

使用

implementation'androidx.cardview:cardview:1.0.0'

答案 1 :(得分:0)

在Java中-您现在可以使用

  

导入androidx.cardview.widget.CardView;

在build.gradle中-

  

实现'androidx.cardview:cardview:1.0.0'

答案 2 :(得分:0)

除了替换

com.android.support:cardview-v7:28.0.0

androidx.cardview:cardview:1.0.0

您仍然需要替换xml并从中导入对象

android.support.v7.widget.CardView

androidx.cardview.widget.CardView

顺便说一句,其他组件也应该更换。 例如:

在gradle中

implementation 'androidx.recyclerview:recyclerview:1.0.0'

代码和xml对象中的

androidx.recyclerview.widget.RecyclerView