3

I'm using Android Studio 1.2.2 and attempting to use the CardView in my layout, but the preview is giving me the warning that the class android.support.v7.widget.CardView could not be found. This question has been asked various times, and I have looked at these solutions:

Error when adding CardView to layout

android.support.v7.widget.CardView could not be found (Android Studio 1.1 Preview)

But none of them have the answer. I have added this to my gradle:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:cardview-v7:21.0.+'
}

and I have added this to the layout:

xmlns:card_view="http://schemas.android.com/apk/res-auto"

which pretty much sums up the answers given on the two similar questions asked, but I am still getting the same error, and when I run it on a device, the CardView doesn't show up at all. Can anyone point out any other possible solutions?

By the way, the minSdkVersion is 21.

Layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent"
android:layout_height="match_parent" 
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" 
tools:context="integraloftan.cardview.main">

<android.support.v7.widget.CardView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:elevation="100dp"
    card_view:cardCornerRadius="8dp">
</android.support.v7.widget.CardView>

and gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "integraloftan.match"
        minSdkVersion 21
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:cardview-v7:22.2.0'
}
Community
  • 1
  • 1
IntegralOfTan
  • 640
  • 6
  • 18

1 Answers1

0

First of all, sorry if I made it unclear: set buildToolsVersion to 22.0.1
Secondly, your CardView doesn't have any children and its height is set to wrap_content, that's probably why you don't see anything. Try setting height to a fixed value like 100dp and see if it appears.

Mikhail
  • 3,666
  • 4
  • 30
  • 43