在我的项目(Eclipse)中使用 android.support.v7.widget.CardView

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24449344/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 08:10:36  来源:igfitidea点击:

Using android.support.v7.widget.CardView in my project (Eclipse)

androideclipseandroid-5.0-lollipopandroid-cardview

提问by FD_

I'd like to use the new CardView widget that was introduced with the new Android L Developer Preview Support Library (As mentioned here), which seems to be part of a new revision of the v7 support library.

我想使用已与新的Android L移动开发者预览版支持库(如前所述引入的新CardView小部件在这里),这似乎是V7支持库的一个新版本的一部分。

I have now updated my SDK version, downloaded the newest Support Library package, but I still cannot find the new CardView widget.

我现在已经更新了我的 SDK 版本,下载了最新的支持库包,但我仍然找不到新的 CardView 小部件。

I already searched the web and the official docs, but could not get any hints on where I can get the new support library.

我已经搜索了网络和官方文档,但无法获得有关从何处获得新支持库的任何提示。

Any help is highly appreciated!

任何帮助表示高度赞赏!

EDIT: I'm using ADT/Eclipse

编辑:我正在使用 ADT/Eclipse

采纳答案by FD_

I finally found a way to use CardView in ADT/Eclipse. It's actually pretty easy:

我终于找到了一种在 ADT/Eclipse 中使用 CardView 的方法。其实很简单:

  1. Create a new project in Android Studio
  2. Add the CardView dependency as explained in the other answers to this question
  3. Open ADT and create a new library project with package name android.support.v7.cardview
  4. Delete all resources ADT auto-created
  5. Find the exploded-aarfolder in Android Studio and copy the following files to these locations:
    • res/values/values.xmlto the same location in your ADT project
    • classes.jarto libs/ in your ADT project
    • AndroidManifest.xmluse it to replace the auto-generated manifest in ADT
  6. Add classes.jar to the build path and make sure it's exported
  7. Add a reference to the library project in the project you want to use CardView in. You can follow the steps provided under Adding libraries with resourceshere: https://developer.android.com/tools/support-library/setup.html
  1. 在 Android Studio 中创建一个新项目
  2. 按照此问题的其他答案中的说明添加 CardView 依赖项
  3. 打开 ADT 并使用包名创建一个新的库项目 android.support.v7.cardview
  4. 删除 ADT 自动创建的所有资源
  5. exploded-aar在 Android Studio 中找到该文件夹并将以下文件复制到这些位置:
    • res/values/values.xml到 ADT 项目中的相同位置
    • classes.jar到 ADT 项目中的 libs/
    • AndroidManifest.xml使用它来替换 ADT 中自动生成的清单
  6. 将 classes.jar 添加到构建路径并确保它已导出
  7. 在要使用 CardView 的项目中添加对库项目的引用。您可以按照Adding libraries with resources此处提供的步骤操作:https: //developer.android.com/tools/support-library/setup.html

As an alternative to having to create a new Android Studio project in order to get the AAR's content, you could also simply find and unzip the AAR from the local maven repo. Just follow the steps provided by Andrew Chen below.

除了必须创建一个新的 Android Studio 项目来获取 AAR 的内容之外,您还可以简单地从本地 maven 存储库中找到并解压缩 AAR。只需按照以下 Andrew Chen 提供的步骤操作即可。

Please note the CardView library might not be available in source- and ADT-compatible-form because it's still only a preview and a WIP. As there might be bug fixes and improvements in following releases, it's important to keep the library up-to-date, which is easy using the Gradle dependency, but must be done manually when using the steps provided above.

请注意 CardView 库可能无法以源代码和 ADT 兼容的形式使用,因为它仍然只是预览和 WIP。由于后续版本中可能会有错误修复和改进,因此保持库是最新的很重要,这很容易使用 Gradle 依赖项,但在使用上面提供的步骤时必须手动完成。

回答by CommonsWare

Using Gradle or Android Studio, try adding a dependency on com.android.support:cardview-v7.

使用 Gradle 或 Android Studio,尝试添加对com.android.support:cardview-v7.

There does not seem to be a regular Android library project at this time for cardview-v7, leanback-v17, palette-v7, or recyclerview-v7. I have no idea if/when Google will ship such library projects.

似乎没有在这个时候是一个普通的Android库项目cardview-v7leanback-v17palette-v7,或recyclerview-v7。我不知道谷歌是否/何时会发布这样的库项目。

回答by adboco

You need to add this in your build.gradle:

您需要在 build.gradle 中添加:

dependencies {
    ...
    compile 'com.android.support:cardview-v7:+'
}

And then Sync Project with Gradle Files. Finally, you can use CardView as it's described here.

然后Sync Project with Gradle Files。最后,您可以按照此处所述使用 CardView 。

回答by Rajat Sharma

I have done following and it resolve an issue with recyclerview same you may use for other widget as well if it's not working in eclipse project.

我已经完成了以下操作,它解决了与 recyclerview 相同的问题,如果它在 eclipse 项目中不起作用,您也可以将其用于其他小部件。

? Go to sdk\extras\android\m2repository\com\android\support\recyclerview-v7\21.0.0-rc1directory

? 进入 sdk\extras\android\m2repository\com\android\support\recyclerview-v7\21.0.0-rc1目录

? Copy recyclerview-v7-21.0.0-rc1.aarfile and rename it as .zip

? 复制recyclerview-v7-21.0.0-rc1.aar文件并将其重命名为 .zip

? Unzip the file, you will get classes.jar(rename the jar file more meaningful name)

? 解压文件,得到classes.jar(重命名jar文件更有意义的名字)

? Use the following jar in your project build path or lib directory.

? 在您的项目构建路径或 lib 目录中使用以下 jar。

and it resolve your error.

它解决了你的错误。

happy coding :)

快乐编码:)

回答by Andrew Chen

https://github.com/yongjhih/CardView

https://github.com/yongjhih/CardView

A CardView v7 eclipse project. (from sdk/extras/android/m2repository/com/android/support/cardview-v7)

CardView v7 eclipse 项目。(来自 sdk/extras/android/m2repository/com/android/support/cardview-v7)

The project was built by steps:

该项目是通过以下步骤构建的:

cp {sdk}/extras/android/m2repository/com/android/support/cardview-v7/21.0.0-rc1/cardview-v7-21.0.0-rc1.aar cardview-v7-21.0.0-rc1.zip
unzip cardview-v7-21.0.0-rc1.zip
mkdir libs/
mv classes.jar libs/cardview-v7-21.0.0-rc1.jar

回答by Roy Doron

I was able to work it out only after adding those two TOGETHER:

只有在将这两个加在一起后,我才能解决它:

dependencies {
...
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'
...
}

in my build.gradle (Module:app)file

在我的 build.gradle (Module:app)文件中

and then press the sync nowbutton

然后按立即同步按钮

回答by Eloi Navarro

Although a bit hidden it's in the official docs herewhere can the library be found among the sdk's code, and how to get it with resources (the Eclipse way)

虽然有点隐藏,但它在这里官方文档中可以在 sdk 的代码中找到该库,以及如何使用资源获取它(Eclipse 方式)

回答by I'm_With_Stupid

From: https://developer.android.com/tools/support-library/setup.html#libs-with-res

来自:https: //developer.android.com/tools/support-library/setup.html#libs-with-res

Adding libraries with resources To add a Support Library with resources (such as v7 appcompat for action bar) to your application project:

添加带有资源的库 将带有资源的支持库(例如 v7 appcompat for action bar)添加到您的应用程序项目:

Using Eclipse

使用 Eclipse

Create a library project based on the support library code:

根据支持库代码创建一个库项目:

  • Make sure you have downloaded the Android Support Library using the SDK Manager.

  • Create a library project and ensure the required JAR files are included in the project's build path:

  • Select File > Import.

  • Select Existing Android Code Into Workspace and click Next.

  • Browse to the SDK installation directory and then to the Support Library folder. For example, if you are adding the appcompat project, browse to /extras/android/support/v7/appcompat/.

  • Click Finish to import the project. For the v7 appcompat project, you should now see a new project titled android-support-v7-appcompat.

  • In the new library project, expand the libs/ folder, right-click each .jar file and select Build

  • Path > Add to Build Path. For example, when creating the the v7 appcompat project, add both the android-support-v4.jar and android-support-v7-appcompat.jar files to the build path.

  • Right-click the library project folder and select Build Path > Configure Build Path.

  • In the Order and Export tab, check the .jar files you just added to the build path, so they are available to projects that depend on this library project. For example, the appcompat project requires you to export both the android-support-v4.jar and android-support-v7-appcompat.jar files.

  • Uncheck Android Dependencies.

  • Click OK to complete the changes.

  • You now have a library project for your selected Support Library that you can use with one or more application projects.

  • Add the library to your application project:

  • In the Project Explorer, right-click your project and select Properties.

  • In the category panel on the left side of the dialog, select Android.

  • In the Library pane, click the Add button.

  • Select the library project and click OK. For example, the appcompat project should be listed as android-support-v7-appcompat.

  • In the properties window, click OK.

  • 确保您已使用 SDK 管理器下载了 Android 支持库。

  • 创建一个库项目并确保所需的 JAR 文件包含在项目的构建路径中:

  • 选择文件 > 导入。

  • 选择 Existing Android Code Into Workspace 并单击 Next。

  • 浏览到 SDK 安装目录,然后浏览到 Support Library 文件夹。例如,如果您要添加 appcompat 项目,请浏览至 /extras/android/support/v7/appcompat/。

  • 单击完成以导入项目。对于 v7 appcompat 项目,您现在应该会看到一个名为 android-support-v7-appcompat 的新项目。

  • 在新建的库项目中,展开 libs/ 文件夹,右键单击每个 .jar 文件并选择 Build

  • 路径 > 添加到构建路径。例如,在创建 v7 appcompat 项目时,将 android-support-v4.jar 和 android-support-v7-appcompat.jar 文件添加到构建路径。

  • 右键单击库项目文件夹并选择构建路径 > 配置构建路径。

  • 在 Order and Export 选项卡中,检查您刚刚添加到构建路径的 .jar 文件,以便它们可用于依赖于该库项目的项目。例如,appcompat 项目要求您导出 android-support-v4.jar 和 android-support-v7-appcompat.jar 文件。

  • 取消选中 Android 依赖项。

  • 单击确定以完成更改。

  • 您现在拥有了一个用于所选支持库的库项目,您可以将其用于一个或多个应用程序项目。

  • 将库添加到您的应用程序项目:

  • 在 Project Explorer 中,右键单击您的项目并选择 Properties。

  • 在对话框左侧的类别面板中,选择 Android。

  • 在库窗格中,单击添加按钮。

  • 选择库项目并单击确定。例如,appcompat 项目应列为 android-support-v7-appcompat。

  • 在属性窗口中,单击确定。

回答by Michelle

Maybe it's a little bit late to add answer here. But I think this answer will help the later ones and especially those who don't want to use Android Studio.

也许在这里添加答案有点晚了。但我认为这个答案会对后来的人,尤其是那些不想使用 Android Studio 的人有所帮助。

Although the documents says that RecyclerView and CardView are part of v7 appcompat library. But as I tried and found, RecyclerView and CardView are actually depend on v7 appcompat library. So if you want to use RecyclerView or CardView, you need to add both v7 appcompat library and RecyclerView/CardView.

尽管文档说 RecyclerView 和 CardView 是 v7 appcompat 库的一部分。但正如我尝试发现的,RecyclerView 和 CardView 实际上依赖于 v7 appcompat 库。所以如果要使用RecyclerView或者CardView,需要同时添加v7 appcompat库和RecyclerView/CardView。

Referencing the link here, if you want to use CardView in your Eclipse android project, you need to import both v7 appcompat library and CardView into Eclipse workspace and make them as library projects. Then make CardView project depends on v7 appcompat library project and make your project depends on CardView project.

参考这里的链接,如果你想在你的 Eclipse android 项目中使用 CardView,你需要将 v7 appcompat 库和 CardView 导入 Eclipse 工作区,并将它们作为库项目。然后使 CardView 项目依赖于 v7 appcompat 库项目并使您的项目依赖于 CardView 项目。

回答by Pihu

Simply add the following line in your build.gradleproject

只需在您的build.gradle项目中添加以下行

dependencies {
    ...
    compile 'com.android.support:cardview-v7:24.0.0'
}

And sync the project with gradle.

并将项目与 gradle 同步。