How to add the recyclerview to project

谁说我不能喝 提交于 2020-01-01 07:53:52

问题


tried to import android.support.v7.widget.RecyclerView, but it didn't work, added also

compile 'com.android.support:recyclerview-v7:23.1.1'

to build.gradle, but it didn't help either


回答1:


you can also add lib/dependencies from android studio menu.

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.




回答2:


  1. Open build.gradle and add recycler view dependency. com.android.support:recyclerview-v7:23.1.1 and rebuild the project.

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'}
  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.

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>



回答3:


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:

<android.support.v7.widget.RecyclerView
    android:id="@+id/recycler_view"
    android:scrollbars="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>



回答4:


Update this Dependency Latest

compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.android.support:design:25.3.1'



回答5:


Only putting this

implementation'com.android.support:design:25.3.1'

Will also work.



来源:https://stackoverflow.com/questions/37612348/how-to-add-the-recyclerview-to-project

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