如何导入 RecyclerView for Android L-preview
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24440852/
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 import RecyclerView for Android L-preview
提问by micnoy
Trying to use the new RecyclerView from the support library. I downloaded the 20 update for the support library using the SDK manager.
尝试使用支持库中的新 RecyclerView。我使用 SDK 管理器下载了支持库的 20 更新。
I've added the jar file to the libs folder - and added to build path - no luck using the RecyclerView.
我已将 jar 文件添加到 libs 文件夹 - 并添加到构建路径 - 使用 RecyclerView 没有运气。
Tried to use also the gradle dependency according to Android Developer's API- not sure if this is the right place to look - this page is related more to AndroidTV :
根据Android 开发人员的 API,还尝试使用 gradle 依赖项- 不确定这是否是正确的地方 - 此页面与 AndroidTV 相关更多:
com.android.support:recyclerview-v7:20.0.+
Cannot gradle sync the project.
无法 gradle 同步项目。
Any ideas?
有任何想法吗?
采纳答案by Gunaseelan
I have created using following lines and this works for me.
我使用以下几行创建,这对我有用。
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
For AndroidX
对于 AndroidX
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.cardview:cardview:1.0.0'
For complete tutorial please see here
完整教程请看这里
回答by micnoy
Figured it out.
弄清楚了。
You'll have to add the following gradle dependency :
您必须添加以下 gradle 依赖项:
compile 'com.android.support:recyclerview-v7:+'
another issue I had compiling was the compileSdkVersion
. Apparently you'll have to compile it against android-L
我编译的另一个问题是compileSdkVersion
. 显然你必须编译它android-L
Your build.gradle file should look something like this:
您的 build.gradle 文件应如下所示:
apply plugin: 'android'
android {
compileSdkVersion 'android-L'
buildToolsVersion '19.1.0'
[...]
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:recyclerview-v7:+'
}
回答by Andras K
This works for me:
这对我有用:
compile 'com.android.support:recyclerview-v7:21.0.0-rc1'
回答by Bryon Nicoson
RecyclerView can now be added by compiling design dependency in app gradle:
现在可以通过在 app gradle 中编译设计依赖来添加 RecyclerView:
dependencies {
...
compile 'com.android.support:design:24.0.0'
}
回答by yubaraj poudel
If You have Compiled SDK Version 22.2.0 then add below dependency for recycler view and cardview additional for support of cardView
如果您已编译 SDK 版本 22.2.0,则为回收器视图和 cardview 添加以下依赖项以支持 cardView
// for including all the libarary in the directory libcompile fileTree(include: ['*.jar'], dir: 'libs')
// for support appcompatcompile 'com.android.support:appcompat-v7:22.2.0'
//for including google support design (it makes possible of implementing material design theme from 2.3 and higher)
`compile 'com.android.support:design:22.2.0'
//用于包含目录 lib 中的所有库compile fileTree(include: ['*.jar'], dir: 'libs')
//用于支持 appcompatcompile 'com.android.support:appcompat-v7:22.2.0'
//用于包含谷歌支持设计(它可以实现 2.3 及更高版本的材料设计主题)
`compile 'com.android.support:design:22.2. 0'
for adding the recycler view use following dependency
compile 'com.android.support:recyclerview-v7:22.2.0'
添加回收器视图使用以下依赖项
compile 'com.android.support:recyclerview-v7:22.2.0'
After that click on Build->rebuild project and you are done.
之后点击 Build->rebuild project 就完成了。
回答by Dino Sunny
compile 'com.android.support:recyclerview-v7:24.2.1'
This works for me. Try it.
这对我有用。尝试一下。
回答by Azzy
include the dependency in the build.gradle
, and sync the project with gradle
files
在 中包含依赖项build.gradle
,并将项目与gradle
文件同步
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:25.1.0'
//include the revision no, i.e 25.1.1
implementation 'com.android.support:recyclerview-v7:25.1.1'
}
Include the revision(here its 25.1.1) to avoid unpredictable builds, check library revisions
包括修订(这里是 25.1.1)以避免不可预测的构建,检查库修订
回答by Junior Hazel
The steps before me are just missing one step.
眼前的台阶,只是少了一步。
After altering the build.gradle(Module:app) and adding the following dependencies:
更改build.gradle(Module:app) 并添加以下依赖项后:
compile 'com.android.support:cardview-v7:21.0.+'
compile 'com.android.support:recyclerview-v7:21.0.+'
编译'com.android.support:cardview-v7:21.0.+'
编译'com.android.support:recyclerview-v7:21.0.+'
(Add cardview if necessary)
(必要时添加cardview)
You must then must go to Build > Clean Projectto get rid of any errors
然后,您必须转到Build > Clean Project以消除任何错误
回答by yubaraj poudel
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:recyclerview-v7:21.0.0'
}
Just make your dependencies like above in build.gradle file, worked for me.
只需在 build.gradle 文件中像上面一样创建您的依赖项,就可以为我工作。
回答by Samuele Bolognini
in my case I fixed it by putting compile 'com.android.support:recyclerview-v7:22.0.0'
as a dependency into my gradle build
就我而言,我通过将其compile 'com.android.support:recyclerview-v7:22.0.0'
作为依赖项放入我的 gradle 构建中来修复它
(with Android studio v. 1.2.1.1 and all sdk's updated.)
(使用 Android studio v. 1.2.1.1 和所有 sdk 更新。)
It's really annoying when codes are updated so fast and the IDE can't keep track of them, and you have to manually fix for them, wasting time and resources.
当代码更新如此之快而IDE无法跟踪它们时,这真的很烦人,您必须手动修复它们,浪费时间和资源。
But well, at last it works.
但是,好吧,它终于奏效了。