1. 外层布局 用RecylerView
<?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/rv_list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
2. 设置GridLayoutManager
var layoutManager = GridLayoutManager(context,entity.size,RecyclerView.HORIZONTAL,false)
四个参数分别是:上下文、一个页面展示的数量、方向、是否转向
3. 设置内层布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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">
<ImageView
android:id="@+id/iv_book_img"
android:layout_width="@dimen/px_200"
android:layout_height="@dimen/px_110"
android:layout_centerInParent="true"
android:src="@mipmap/book_default" />
</RelativeLayout>
网友评论