1.RecycleView
1.1简介
从
Android 5.0
开始,谷歌公司推出了一个用于
大量数据展示的新控件
RecylerView
,可以用来代替
传统的
ListView
,更加强大和灵活。
RecyclerView
是一个强大的滑动组件,与经典的
ListView
相比,同样拥有
item
回收复用的功能,这
一点从它的名字
Recyclerview
即回收
view
也可以看出。
RecyclerView
支持
线性布局
、
网格布局
、
瀑布流布局
三种,而且同时还能够控制横向还是纵向滚
动。
1.2使用流程
1.2.1布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_address"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
1.2.2创建子布局。然后在子布局中,写好自己的子项布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:orientation="vertical"
android:background="@color/teal_200"
android:layout_height="60dp">
<ImageView
android:id="@+id/iv_img"
android:layout_width="90dp"
android:layout_height="30dp"
android:layout_gravity="center"
app:srcCompat="@mipmap/baocun01" />
<TextView
android:id="@+id/tv_name"
android:la