Android Studio 3.5+ 使用androidx的recyclerView

Android逐渐淘汰support之前的版本,Android studio 导入support.v7也会出错。

在Android developers中找到了添加依赖项的方法:

dependencies {

def recyclerview_version = "1.0.0"

implementation "androidx.recyclerview:recyclerview:$recyclerview_version"

// For control over item selection of both touch and mouse driven selection

implementation "androidx.recyclerview:recyclerview-selection:$recyclerview_version"

}

在build.gradle(Module:app)中找到dependencies,在括号里面输入上述文字。修改布局文件如下:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="match_parent"

    android:layout_height="match_parent">

    <androidx.recyclerview.widget.RecyclerView

        android:id="@+id/recycler_view"

        android:layout_width="match_parent"

        android:layout_height="match_parent"/>

</LinearLayout>

然后就可以使用了

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容