【问题标题】:How to add the recyclerview to project如何将回收站视图添加到项目中
【发布时间】:2016-10-03 09:36:23
【问题描述】:

尝试导入android.support.v7.widget.RecyclerView,但是没用,还加了

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

构建.gradle,但也没有帮助

【问题讨论】:

  • 发布您的build.gradle 文件和错误
  • 发布也和布局

标签: java android android-recyclerview


【解决方案1】:

构建 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 文件:

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

【讨论】:

    【解决方案2】:
    1. 打开 build.gradle 并添加回收器视图依赖项。 com.android.support:recyclerview-v7:23.1.1 并重建项目。

    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. 使用最新版本的构建工具,Android Studio 正在为每个活动创建两个布局文件。对于主要活动,它创建了 activity_main.xml(包含 CoordinatorLayout 和 AppBarLayout)和 content_main.xml(用于实际内容)。打开 content_main.xml 和回收站视图小部件。

    布局

    <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】:

      您还可以从 android studio 菜单中添加 lib/dependencies。

      点击“Build” -> “Edit Libraries and Dependencies”。 然后点击右侧的“+”按钮。

      搜索任何库。

      示例搜索“回收商”

      然后从列表中选择“com.android.support:recyclerview-v7:x.x.x”并完成。

      【讨论】:

      • 这是最好的答案,但仍不完美。搜索会产生各种库的负载,但不会产生您需要的回收器;它可以显示最新版本,而不是您需要的版本;可能值得完善答案,因为它似乎很有用。
      【解决方案4】:

      最新更新此依赖项

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

      【讨论】:

        【解决方案5】:

        只放这个

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

        也可以。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-02-25
          • 1970-01-01
          • 1970-01-01
          • 2015-07-27
          • 1970-01-01
          • 2021-07-20
          相关资源
          最近更新 更多