将 android.support.v7.widget.CardView 导入 Eclipse 时遇到问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26719127/
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-09-19 22:10:03  来源:igfitidea点击:

Trouble importing android.support.v7.widget.CardView into Eclipse

javaandroideclipseandroid-support-librarymaterial-design

提问by End.Game

I use Eclipse and I'm trying to create an application using the new support-library-v7:21.+from Lollipop.

我使用 Eclipse,并且正在尝试使用support-library-v7:21.+Lollipop的新功能创建一个应用程序。

  • Created my new project
  • imported in eclipse the support-library-v7
  • changed in project-propertiesof support library the line: target=android-21with 21 target
  • changed the target of my application in 21
  • imported the library in my project
  • clean all
  • 创建了我的新项目
  • 在eclipse中导入 support-library-v7
  • 更改project-properties了支持库的行:target=android-21有 21 个目标
  • 在 21 更改了我的应用程序的目标
  • 在我的项目中导入了库
  • 清洁一切

After all i still got the invalid Rdeclaration. I restarted Eclipse and then, after re-importing the library, seem went! I created a Tolbarand a NavigationDraweras well without problem - it works.

毕竟我还是得到了无效的R声明。我重新启动了 Eclipse,然后在重新导入库后,似乎就行了!我也毫无问题地创建了 aTolbar和 a NavigationDrawer- 它有效。

Now, i would like to put a CardViewin my ListViewitems:

现在,我想CardView在我的ListView物品中放入一个:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
   >
    <!-- A CardView that contains a TextView -->
    <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="200dp"
        card_view:cardCornerRadius="4dp">
    <TextView
        android:id="@+id/name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />
    <TextView
        android:id="@+id/codename"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />
    <TextView
        android:id="@+id/versione"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />
    <TextView
        android:id="@+id/link"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />
    <TextView
        android:id="@+id/timestamp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />

    </android.support.v7.widget.CardView>
</LinearLayout>

well, first error: No resource identifier found for attribute 'cardCornerRadius'. I tried to delete the attribute, restart the application but I get a the following crash:

好吧,第一个错误:No resource identifier found for attribute 'cardCornerRadius'。我试图删除该属性,重新启动应用程序,但出现以下崩溃:

java.lang.RuntimeException: Binary XML file line #2: You must supply a layout_width attribute.

I don't understand what the problem is.

我不明白问题是什么。

回答by shkschneider

Adding the library

添加库

Gradle

摇篮

compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.android.support:cardview-v7:22.0.0'

Eclipse

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

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

Proper LinearLayout

正确的线性布局

As the error said, a LinearLayoutneeds a layout_widthand a layout_heighth. Always.

正如错误所说, aLinearLayout需要 alayout_width和 a layout_heighth。总是。

回答by udit

I have outlined the steps that worked for me as an answer to this question. It should work.

我已经概述了对我有用的步骤作为这个问题的答案。它应该工作。

回答by Maddy

I had the same issue.

我遇到过同样的问题。

Tried adding Eclipse->properies->Android->Libraries->Add = CardView is not there. Tried Eclipse->properies->JavaBuildPath->Libraries->Add Jars->(select from CardView->libs) did not work.

尝试添加 Eclipse->properies->Android->Libraries->Add = CardView 不存在。试过 Eclipse->properies->JavaBuildPath->Libraries->Add Jars->(select from CardView->libs) 没有用。

what worked: cardview->project.properites, add android.library=true if missing.

有效的方法:cardview->project.properites,如果缺少则添加 android.library=true。

回答by Akanksha Rathore

We need to do both the things add android.support.v7.widget.CardView as a library project and also add + check it's jar file in java build path

我们需要做两件事,将 android.support.v7.widget.CardView 添加为库项目,并在 java 构建路径中添加 + 检查它的 jar 文件

Go to File -> Import -> Existing Android code into workspace --> Browse (Go to sdk/extras/android/support/v7/cardview) --> Click ok --> Click Finish

转至文件 -> 导入 -> 现有 Android 代码到工作区 --> 浏览(转至 sdk/extras/android/support/v7/cardview)--> 单击确定 --> 单击完成

Right click on cardview project --> Properties --> Android(Left Pane) --> Enable isLibrary (tick the checkbox) --> Apply --> ok

右键单击cardview项目-->属性-->Android(左窗格)-->启用isLibrary(勾选复选框)-->应用-->确定

Right click on your project --> Properties --> Android(Left pane) --> Add (under library) --> cardview --> apply --> ok

右键单击您的项目--> 属性--> Android(左窗格)--> 添加(在库下)--> cardview --> 应用--> 确定

right click on your project again --> build path --> configure build path -->under libraries-->add jar-->expand cardview-->expand libs-->select android.support.v7.widget.CardView.jar

再次右键单击您的项目--> 构建路径--> 配置构建路径--> 在库下--> 添加jar--> 扩展cardview--> 扩展库--> 选择android.support.v7.widget.CardView 。罐

under order and export-->check android.support.v7.widget.CardView.jar-->click

在order和export-->勾选android.support.v7.widget.CardView.jar-->点击

Hope it will work fine.

希望它能正常工作。

回答by SilentKnight

It is obvious that you didn't import the CardViewsupport project as your main project's library. To import CardViewlibrary, you need to do this:
1, first, import CardViewsupport library into you Eclipse. The process should be like this: File-->Import-->Android-->Existing Android Code into Eclipse-->Browse-->.../sdk/extras/android/support/v7/cardview-->OK-->Finish. Then you will see project of android-support-v7-cardviewin your Eclipse in which all resource and jar is.
2, add android-support-v7-cardviewinto your main project as a library. Just like this: right-click your project-->Properties-->Android-->Add, and select android-support-v7-cardviewinto your project.

很明显,您没有将CardView支持项目作为主项目的库导入。要导入CardView库,您需要执行以下操作:
1、首先,将CardView支持库导入您的 Eclipse。过程应该是这样的: File--> Import--> Android--> Existing Android Code into Eclipse--> Browse--> .../sdk/extras/android/support/v7/cardview--> OK--> Finish。然后您将android-support-v7-cardview在 Eclipse 中看到所有资源和 jar 所在的项目。
2、android-support-v7-cardview作为库添加到你的主项目中。就像这样:右键单击您的项目--> Properties--> Android--> Add,然后选择android-support-v7-cardview进入您的项目。

And then, rebuild your project. Errors about CardViewin your project will be finished.

然后,重建您的项目。CardView您的项目中的错误将被完成。

回答by Jorgesys

Inside your build.gradlefile (inside dependencies section) add the last versions for support library and cardViewsupport library:

在您的build.gradle文件内(在依赖项部分)添加支持库和cardView支持库的最新版本:

dependencies {
    ...
    ...
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:cardview-v7:23.0.1'
}