android.support.v7.widget.cardview 找不到
android.support.v7.widget.cardview cannot be found
我正在使用 Android Studio 1.2.2 并尝试在我的布局中使用 CardView,但预览给我的警告是 class android.support。v7.widget.CardView 找不到。这个问题已经被问过很多次了,我看过这些解决方案:
Error when adding CardView to layout
但其中 none 有答案。我已将此添加到我的 gradle:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:cardview-v7:21.0.+'
}
并且我已将其添加到布局中:
xmlns:card_view="http://schemas.android.com/apk/res-auto"
这几乎总结了两个类似问题的答案,但我仍然遇到同样的错误,当我 运行 它在设备上时,CardView 没有出现在全部。谁能指出任何其他可能的解决方案?
顺便说一下,minSdkVersion 是 21。
布局:
<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>
和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'
}
首先,如果我表达不清楚,请见谅:将 buildToolsVersion
设置为 22.0.1
其次,您的 CardView
没有任何子项并且其 height
设置为 wrap_content
,这可能就是您什么都看不到的原因。尝试将高度设置为固定值,如 100dp
并查看它是否出现。
我正在使用 Android Studio 1.2.2 并尝试在我的布局中使用 CardView,但预览给我的警告是 class android.support。v7.widget.CardView 找不到。这个问题已经被问过很多次了,我看过这些解决方案:
Error when adding CardView to layout
但其中 none 有答案。我已将此添加到我的 gradle:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:cardview-v7:21.0.+'
}
并且我已将其添加到布局中:
xmlns:card_view="http://schemas.android.com/apk/res-auto"
这几乎总结了两个类似问题的答案,但我仍然遇到同样的错误,当我 运行 它在设备上时,CardView 没有出现在全部。谁能指出任何其他可能的解决方案?
顺便说一下,minSdkVersion 是 21。
布局:
<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>
和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'
}
首先,如果我表达不清楚,请见谅:将 buildToolsVersion
设置为 22.0.1
其次,您的 CardView
没有任何子项并且其 height
设置为 wrap_content
,这可能就是您什么都看不到的原因。尝试将高度设置为固定值,如 100dp
并查看它是否出现。