【问题标题】:Use RecyclerView in earlier versions of Android在早期版本的 Android 中使用 RecyclerView
【发布时间】:2015-01-07 06:09:57
【问题描述】:

我想在我的 Android 应用中使用 RecyclerView。以下是属性:

minSdkVersion="14" (ICS)
compile sdk version="21" (L)
Target sdk version="14" (ICS)

我在 build.gradle 文件的依赖项下添加了compile 'com.android.support:appcompat-v7:21.0.3'。 当我在 XML 中添加 RecyclerView 时,出现以下错误:

The following classes could not be found:
- android.support.v7.widget.RecyclerView (Fix Build Path, Create Class)

XML 代码:

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

我希望应用程序在 ICS 之上的所有设备上运行。请帮我解决这个问题。

【问题讨论】:

    标签: android android-5.0-lollipop android-recyclerview


    【解决方案1】:

    RecyclerView v7 支持库添加到您的build.gradle。有多个 v7 库,每个库都有特定的功能。

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

    【讨论】:

    • @Jaguar 你说你添加了appcompat v7 库
    • 谢谢。在此之后我需要在库中添加任何 jar 吗?
    • @Jaguar 不,jar 和资源将从我上面显示的行中导入。
    【解决方案2】:

    RecyclerView 在它自己的库中:

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

    【讨论】:

      【解决方案3】:

      对于targetSdkVersion 25/compileSdkVersion 25和编译'com.android.support:appcompat-v7:25.3.1'你需要使用编译'com.android.support:recyclerview-v7:25.3.1'

      版本必须相同。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-04-06
        • 1970-01-01
        • 2015-12-12
        • 2010-11-02
        • 2014-02-14
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多