gpt4 book ai didi

找不到 android.support.v7.widget.cardview

转载 作者:太空狗 更新时间:2023-10-29 14:55:56 26 4
gpt4 key购买 nike

我正在使用 Android Studio 1.2.2 并尝试在我的布局中使用 CardView,但预览给我警告说找不到类 android.support.v7.widget.CardView。这个问题已经被问过很多次了,我已经看过这些解决方案:

Error when adding CardView to layout

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

但他们都没有答案。我已将其添加到我的 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>

和渐变:

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.support.v7.widget.cardview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31463869/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com