目录
5、RecyclerView封装和数据适配器打造(适配各种数据,将数据与对应的View绑定)
1、创建首页UI
布局文件
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
//有商品展示,因此界面会出出现上拉刷新,下拉加载更多
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/srl_index"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_index"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
//写在下面,防止嵌套滑动,会被新的元素遮住,两边是字体图标:扫描、信息,中间是搜索框
<androidx.appcompat.widget.Toolbar
android:id="@+id/tb_index"
android:layout_width="match_parent"
android:layout_height="80dp"
android:background="@android:color/transparent"
app:layout_behavior="com.example.latte.ec.main.index.TranslucentBehavior">
<androidx.appcom