我正在开发一个使用 RecyclerView 组件的应用程序。我正在检查我的 build.gradle 文件,它有这些依赖项:
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'
没有 'com.android.support:recyclerview-v7:25.3.1',但我在项目中有一个 RecyclerView (android.support.v7.widget.RecyclerView)。
上面哪个包也包含 RecyclerView?或者我对支持库包有什么不了解的地方?
最佳答案
Which of the packages above also contains the RecyclerView?
没有之一。 RecyclerView
位于 recyclerview-v7
中。
Or is there something I don't understand about the support library packages?
design
对 recyclerview-v7
具有传递依赖性。因此,通过依赖于设计
,您的应用也依赖于recyclerview-v7
。这是自动为您处理的。
您可以进一步简化您的依赖关系,因为design
依赖于appcompat-v7
,所以您不需要自己请求appcompat-v7
:
// 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'
然后,注释掉 support-v4
依赖项,看看是否有构建问题。最有可能的是,您从那里使用的内容已经被其他东西引入,因此您也不需要在 build.gradle
文件中使用该依赖项。
您可以阅读更多关于传递依赖的信息 here .
关于android - 支持库中的 RecyclerView 在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46633995/