首页 > 解决方案 > 当孩子的身高不同时,均匀对齐gridview

问题描述

我有这个 GridView:

<GridView
    android:id="@+id/gridView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:stretchMode="columnWidth"
    android:numColumns="2"
    android:verticalSpacing="10dp"
    android:horizontalSpacing="10dp"
    android:clipToPadding="false"
    android:padding="10dp"
    android:scrollbars="none"
    android:drawSelectorOnTop="true"/>

有 99% 的孩子身高相同。没问题,它看起来像这样。

 ----   ----
|    | |    |
|    | |    |
 ----   ----
 ----   ----
|    | |    |
|    | |    |
 ----   ----
 ----   ----
|    | |    |
|    | |    |
 ----   ----

1% 的情况下,一个孩子可能比他的兄弟姐妹高,结果是

 ----   ----
|    | |    |
|    | |    |
|    |  ----
 ----   ----
|    | |    |
|    | |    |
 ----   ----
 ----   ----
|    | |    |
|    | |    |
 ----   ----

如图所示,孩子 1 与其下方的兄弟重叠。

这就是想要实现的目标:

 ----   ----
|    | |    |
|    | |    |
|    |  ----
 ----
 ----   ----
|    | |    |
|    | |    |
 ----   ----
 ----   ----
|    | |    |
|    | |    |
 ----   ----

如您所见,中间的两个孩子进行了调整,以便孩子 1 有足够的空间来绘制它的视图。

为我的 gridview 尝试了不同的配置,但失败了。我被困住了,需要帮助。

标签: androidgridview

解决方案


kindly refer this url , use Recylerview instead of GridView in xml. https://abhiandroid.com/materialdesign/recyclerview-gridview.html


推荐阅读