Java 如何将recyclerview添加到项目中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37612348/
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 the recyclerview to project
提问by Alexander Golubev
tried to import android.support.v7.widget.RecyclerView, but it didn't work, added also
尝试导入 android.support.v7.widget.RecyclerView,但没用,还添加了
compile 'com.android.support:recyclerview-v7:23.1.1'
to build.gradle, but it didn't help either
build.gradle,但它也没有帮助
采纳答案by Nishant Pardamwar
you can also add lib/dependencies from android studio menu.
您还可以从 android studio 菜单添加库/依赖项。
click on "Build" -> "Edit Libraries and Dependencies". then click on "+" button on right side.
单击“构建”->“编辑库和依赖项”。然后点击右侧的“ +”按钮。
search any lib.
搜索任何库。
example search "recycler"
示例搜索“回收商”
then select "com.android.support:recyclerview-v7:x.x.x" from list and your done.
然后从列表中选择“ com.android.support:recyclerview-v7:xxx”并完成。
回答by Nenco
build gradle:
构建梯度:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1'
}
xml file:
xml文件:
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
回答by Elango
- Open build.gradle and add recycler view dependency. com.android.support:recyclerview-v7:23.1.1 and rebuild the project.
- 打开 build.gradle 并添加回收器视图依赖项。com.android.support:recyclerview-v7:23.1.1 并重建项目。
build.gradle
构建.gradle
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1'}
- With the latest version of build tools, Android Studio is creating two layout files for each activity. For main activity, it created activity_main.xml (contains CoordinatorLayout and AppBarLayout) and content_main.xml (for the actual content). Open content_main.xml and the recycler view widget.
- 使用最新版本的构建工具,Android Studio 为每个活动创建两个布局文件。对于主要活动,它创建了activity_main.xml(包含CoordinatorLayout 和AppBarLayout)和content_main.xml(用于实际内容)。打开 content_main.xml 和回收器视图小部件。
Layout
布局
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical" />
</RelativeLayout>
回答by Keshav Gera
Update this Dependency Latest
更新这个依赖最新
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
回答by OhhhThatVarun
Only putting this
只放这个
implementation'com.android.support:design:25.3.1'
Will also work.
也会工作。