美文网首页
GridLayoutManager竖向摆放

GridLayoutManager竖向摆放

作者: 小赵不在 | 来源:发表于2020-12-14 17:37 被阅读0次

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>

相关文章

网友评论

      本文标题:GridLayoutManager竖向摆放

      本文链接:https://www.haomeiwen.com/subject/cgtbgktx.html