我刚刚新建了一个尝试CardView类的项目。我知道它需要一个额外的.jar库。所以我在\ sdk \ extra ... \ support \中找到了cardview-v7-23.0.1-sources.jar cardview-v7 \ 23.0.1。我将其复制并粘贴到我的新项目 - “libs”目录并添加为库。但是我仍然无法在Activity中使用CardView,为什么?
答案 0 :(得分:0)
如果您使用的是androidd studio:
应用程序/的build.gradle
dependencies {
...
compile 'com.android.support:cardview-v7:23.1.0'
}
或者如果您使用eclipse必须下载支持库
最后使用它
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
</android.support.v7.widget.CardView
编辑后
repositories{
flatDir {
dirs 'libs'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
并同步项目
答案 1 :(得分:0)
如果您使用的是Android工作室
首先将您的sdk更新为最新版本。
为build.gradle文件添加依赖项
'com.android.support:cardview-v7:23.1.0'
将以下代码添加到您的xml文件中。
<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="100dp"
card_view:cardCornerRadius="4dp">
</android.support.v7.widget.CardView>
答案 2 :(得分:0)
尝试使用
dependencies {compile files('libs/yourcardviewjarname.jar')}