用于RecyclerView Android的自定义网格布局

用于RecyclerView Android的自定义网格布局,android,grid-layout,Android,Grid Layout,我需要这样的网格布局构建 我已经创建了RecyclerView并设置了GridLayoutManager <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content"> <ImageView android:id

我需要这样的网格布局构建

我已经创建了RecyclerView并设置了GridLayoutManager

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:layout_height="wrap_content">

   <ImageView
       android:id="@+id/imgPost"
       android:scaleType="centerCrop"
       android:layout_width="match_parent"
       android:layout_height="match_parent" />
</RelativeLayout>


但它会产生空的空间。请帮我实现这一点。

您要找的是

试试这个-

StaggeredGridLayoutManager gridLayoutManager;
gridLayoutManager = new StaggeredGridLayoutManager(3, 1);
recyclerView.setLayoutManager(gaggeredGridLayoutManager);

希望这有帮助

对于此类
GridView
使用
StaggedGridLayout
添加了一些代码来解释如何使用交错网格布局,谢谢