Where is the RecyclerView in the support library?

五迷三道 提交于 2021-02-10 03:17:04

问题


I'm working on an app which uses the RecyclerView component. I was checking my build.gradle file and it had these dependencies:

compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.0-beta5'
compile 'com.android.support:design:25.3.1'
testCompile 'junit:junit:4.12'
compile 'com.android.support:support-v4:25.3.1'

There was no 'com.android.support:recyclerview-v7:25.3.1', and yet I had a RecyclerView (android.support.v7.widget.RecyclerView) in the project.

Which of the packages above also contains the RecyclerView? Or is there something I don't understand about the support library packages?


回答1:


Which of the packages above also contains the RecyclerView?

None of them. RecyclerView is in recyclerview-v7.

Or is there something I don't understand about the support library packages?

design has a transitive dependency upon recyclerview-v7. Hence, by depending upon design, your app also depends upon recyclerview-v7. This is handled for you automatically.

You could simplify your dependencies further, as design depends upon appcompat-v7, so you do not need to request appcompat-v7 yourself:

// compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.0-beta5'
compile 'com.android.support:design:25.3.1'
testCompile 'junit:junit:4.12'
compile 'com.android.support:support-v4:25.3.1'

Then, comment out the support-v4 dependency and see if you have build problems. Most likely, what you are using from there is pulled in by something else already, and so you will not need that dependency in your build.gradle file either.

You can read more about transitive dependencies here.




回答2:


just add it in your app gradle

compile "com.android.support:recyclerview-v7:25.3.1



来源:https://stackoverflow.com/questions/46633995/where-is-the-recyclerview-in-the-support-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!