0

I have a simple application which collapses as I run it. When I remove the CardView view the app runs appropriately.

How can I add the CardView view appropriately?

I suspect that the right decleration of the CardView view should be different then: android.support.v7.widget.CardView.

Here's activity.main.xml:

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <android.support.v7.widget.CardView
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:id="@+id/card_view"
        android:layout_gravity="center"
        android:layout_width="200dp"
        android:layout_height="200dp"
        card_view:cardCornerRadius="4dp">

        <TextView
            android:id="@+id/info_text"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

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

</LinearLayout>

Here's build.gradle (Module: app):

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "android.example.blah1111"
        minSdkVersion 15
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'com.android.support:cardview-v7:29.0.0'
}
J. Doe
  • 299
  • 3
  • 12

1 Answers1

2

EDITED

You have appcompat dependency, which contains correct version of CardView. So, just change the reference from android.com to androidx in your XML. Don't forget to get rid of old unused dependency. Also take a look at this article https://developer.android.com/jetpack/androidx/migrate

aspix
  • 425
  • 2
  • 9
  • 1
    Actually the specific line `androidx.cardview:cardview` did not help me, but when I typed `androidx.` AS suggested me to use the decleration `androidx.cardview.widget.CardView` which solved the problem. Thanks! – J. Doe Oct 13 '19 at 14:40
  • `com.android.support:cardview-v7:29.0.0` does not exist and should be removed. – Martin Zeitler Oct 13 '19 at 19:34