1、直接将recycleview的manager改成上面的即可,如下:
private StaggeredGridLayoutManager manager;
manager=new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL);
recyclerView.setLayoutManager(manager);
2、另外,adapter的布局item的根布局的高一定是match_parent;,图片的高度或其主layout的高为wrap_content,如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_marginTop="@dimen/dp_10"
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:layout_width="@dimen/dp_162"
android:layout_height="wrap_content"
android:background="@drawable/btn_black_redius_4_background">
<ImageView
android:id="@+id/item_model_img_resource"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"/>
</RelativeLayout>
</LinearLayout>
</LinearLayout>