# Android_Recyclerview_list **Repository Path**: lduml/Android_Recyclerview_list ## Basic Information - **Project Name**: Android_Recyclerview_list - **Description**: recyclerview 简单使用 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-02-21 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # recyclerview 简单使用 ## AndroidX 在 Android Pie 以后引入了androidx库,代码库逐渐迁移到androidx下 AndroidX下 RecyclerView AppCompatActivity ``` import androidx.appcompat.app.AppCompatActivity; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; ``` 旧代码可以使用工具进行转换build.gradle, 工具栏 Refactor --> migrate to AndroidX ``` Version 28 (intended for Android Pie and below) is the last version of the legacy support library, so we recommend that you migrate to AndroidX libraries when using Android Q and moving forward. The IDE can help with this: Refactor --> migrate to AndroidX 转换 前 后 // implementation 'com.android.support:recyclerview-v7:28.0.0' implementation 'androidx.recyclerview:recyclerview:1.0.0' ``` 可在gradle.properties中看到启用AndroidX的相关代码: ``` android.useAndroidX=true android.enableJetifier=true ``` 第一行代码表示当前项目是否启用androidx,第二行代码表示是否将依赖包迁移至androidx。 因此新建布局时需要以androidx为路径的开头, ## 需要注意的地方 页面布局中, java文件中, 引用 ## 自定义 recyclerview的布局 /layout/item_rv.xml ```xml ``` 其中 layout_width,layout_height ,代表了在list中单条 item的布局,若layout_height设置为 match_parent 单条布局将会铺满整个屏幕,所以需要注意这里 ``` android:layout_width="match_parent" android:layout_height="wrap_content" ``` 若单个item中有图片,button等其它控件,都可以在item_rv.xml进行添加