eclipse 如何在布局xml中添加回收视图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26094818/
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
How to add recycle view in layout xml
提问by DCoder
I am following this link, as mentioned in the link I am trying to add recycle view as follows:
我正在关注此链接,如链接中所述,我正在尝试添加回收视图,如下所示:
<android.support.v7.widget.RecyclerView
android:id="@+id/my_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" />
I have added android-support-v7-appcompat
library project and also tried adding recyclerview-v7-21.0.0-rc1.aar
to libs
but still I am getting following error.
我添加了android-support-v7-appcompat
库项目并尝试添加recyclerview-v7-21.0.0-rc1.aar
,libs
但仍然出现以下错误。
The following classes could not be found:
- android.support.v7.widget.RecyclerView
The following classes could not be found:
- android.support.v7.widget.RecyclerView
Note: I have updated Android SDK Tools, Android SDK Platform Tools, Android SDK Build Tools, Android L (API 20, L Preview)
注意:我已经更新了 Android SDK 工具、Android SDK 平台工具、Android SDK 构建工具、Android L(API 20,L 预览版)
please help..
请帮忙..
回答by Gabriele Mariotti
You can't add the aarfile to libs folder in Eclipse (it isn't a jar file)
您无法将 aar文件添加到 Eclipse 中的 libs 文件夹(它不是 jar 文件)
The best wayto work with the new RecyclerView
is, currently, to switch to Android Studioand add this dependency to your build.gradle
RecyclerView
目前,使用新版本的最佳方法是切换到Android Studio并将此依赖项添加到您的 build.gradle
compile 'com.android.support:recyclerview-v7:+'
Just a note.It is not a good practice to use the '+' placeholder, but in this case you are trying a preview release, so it will be update soon with stable release.
只是一个注释。使用“+”占位符不是一个好习惯,但在这种情况下,您正在尝试预览版本,因此它将很快通过稳定版本进行更新。
You can use one of these versions. Check your sdk for updated version:
您可以使用这些版本之一。检查您的 sdk 以获取更新版本:
//it requires compileSdkVersion 23
compile 'com.android.support:recyclerview-v7:23.3.0'
compile 'com.android.support:recyclerview-v7:23.2.1'
compile 'com.android.support:recyclerview-v7:23.2.0'
compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.0'
compile 'com.android.support:recyclerview-v7:23.0.1'
compile 'com.android.support:recyclerview-v7:23.0.0'
//it requires compileSdkVersion 22
compile 'com.android.support:recyclerview-v7:22.2.1'
compile 'com.android.support:recyclerview-v7:22.2.0'
compile 'com.android.support:recyclerview-v7:22.1.1'
compile 'com.android.support:recyclerview-v7:22.1.0'
compile 'com.android.support:recyclerview-v7:22.0.0'
//it requires compileSdkVersion 21
compile 'com.android.support:recyclerview-v7:21.0.3'
compile 'com.android.support:recyclerview-v7:21.0.2'
compile 'com.android.support:recyclerview-v7:21.0.0'
Of course you can still use Eclipsebut it will requires some manual operations.
You can find all the release of the support libraries library in this folder:
当然,您仍然可以使用Eclipse,但它需要一些手动操作。
您可以在此文件夹中找到支持库库的所有版本:
sdk/extras/android/m2repository/com/android/support/
Here you can check all version.
In the folders you will find the aar
file of the support libraries.
Inside you can check the classes.jar
file,the res folder and the AndroidManifest file.
在这里您可以查看所有版本。
在文件夹中,您将找到aar
支持库的文件。在里面你可以检查classes.jar
文件、res 文件夹和 AndroidManifest 文件。
Create a project in your workspace
Unzip the AAR into some directory.
Copy the
AndroidManifest.xml
, theres
, andassets
folders from the AAR into your project.Create a
libs
directory in your project and copy into it theclasses.jar
Add the dependency.
Use the SDK 23 to compile
Mark the project as a library
在您的工作区中创建一个项目
将 AAR 解压缩到某个目录中。
将AAR 中
AndroidManifest.xml
的res
、 和assets
文件夹复制到您的项目中。libs
在您的项目中创建一个目录并将其复制到其中classes.jar
添加依赖项。
使用SDK 23编译
将项目标记为库
The Recyclerviewlibrary has the support-v4.jar
and the support-annotations-23.x.X.jar
as dependencies.
该Recyclerview库具有support-v4.jar
与支持-annotations-23.x.X.jar
作为依赖。
回答by mfaisalhyder
ECLIPSE
蚀
If your problem is not solved or for future readers , here is the answer: From android sdk manager download Android Support Library first.
如果您的问题没有解决,或者对于未来的读者,这里是答案:首先从 android sdk 管理器下载 Android 支持库。
Go to this location and copy .aar file from here
转到此位置并从此处复制 .aar 文件
X:\android-sdk\extras\android\m2repository\com\android\support\recyclerview-v7\21.0.0
X:\android-sdk\extras\android\m2repository\com\android\support\recyclerview-v7\21.0.0
Then rename it as .zip file then unZIP it then find classes.jar file , rename it with some proper name like 'RecyclerView_v7.jar' Then copy the that .jar file in you project library. Add it to build path then restart eclipse so that it can be instantiated (not necessary but i had to do this).
然后将其重命名为 .zip 文件,然后解压缩它,然后找到 classes.jar 文件,将其重命名为诸如“RecyclerView_v7.jar”之类的适当名称,然后将该 .jar 文件复制到您的项目库中。将它添加到构建路径然后重新启动 eclipse 以便它可以被实例化(不是必需的,但我必须这样做)。
**=================================Update=======================**
After new Library Updates; RecyclerView,CardView etc are available as simple library projects.! :)
新库更新后;RecyclerView、CardView 等可作为简单的库项目使用。!:)
File~>Import~>Existing Android Code~>SDKpath~>extras~>android~>support~> v7~>recyclerView.
File~> Import~> Existing Android Code~> SDKpath~> extras~> android~> support~> v7~> recyclerView。
Then right click on this project , go to properties under Androidcheck Is Library. It is done ..!
然后右键单击该项目,转到Android下的属性检查Is Library。完成了..!
Now open your app in which you want to use recyclerView. goto properties of your app Project under Androidadd Library here you will find that Library project add that (remember don't make your app a library project by checking 'Is Library'), now go to your App Project's
现在打开您要在其中使用 recyclerView 的应用程序。goto properties of your app Project under Androidadd Library here 你会发现Library project添加了那个(记住不要通过选中'Is Library'来让你的应用成为一个库项目),现在去你的应用项目
Properties~>Java Build Path~>Libraries~>Add Jars~>RecyclerView LibraryProject~>libs
Properties~> Java Build Path~> Libraries~> Add Jars~> RecyclerView LibraryProject~> libs
Then add that jar into your project and buildpath .! Pheeew.. :)
然后将该 jar 添加到您的项目和 buildpath 中。噗.. :)