Android GridView';滚动时,s列不是一条直线

Android GridView';滚动时,s列不是一条直线,android,gridview,android-gridview,Android,Gridview,Android Gridview,我正在开发一个包含许多图像的Android GridView当滚动到列表底部后向上滚动时,列表的列不再是一条直线。 截图: 更奇怪的是,即使使用相同的适配器和GridView,在另一个列表(截图的残奥会选项卡)中也不会出现这种反应。但另一个页面的项目较少。因此,我认为项目的差异是否重要。(我猜)问题单上有40项 代码: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://sch

我正在开发一个包含许多图像的Android GridView当滚动到列表底部后向上滚动时,列表的列不再是一条直线。

截图:

更奇怪的是,即使使用相同的适配器和GridView,在另一个列表(截图的残奥会选项卡)中也不会出现这种反应。但另一个页面的项目较少。因此,我认为项目的差异是否重要。(我猜)问题单上有40项

代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="5dp"
    android:background="@color/white">

    <GridView
        android:id="@+id/sports_gridView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="4dp"
        android:columnWidth="80dp"
        android:gravity="center"
        android:numColumns="auto_fit"
        android:stretchMode="columnWidth"/>

</LinearLayout>

适配器

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingLeft="5dp"
    android:paddingRight="5dp"
    android:paddingTop="10dp"
    android:paddingBottom="20dp"
    android:background="@color/white">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <ImageView
            android:id="@+id/sports_iv_item_icon"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_marginRight="10dp"
            android:layout_centerHorizontal="true"/>

    </RelativeLayout>


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/sports_tv_item_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:gravity="center"
            android:textSize="12dp"
            android:textColor="@color/black"
            android:layout_centerHorizontal="true"/>

    </RelativeLayout>


</LinearLayout>

为什么会出现这种现象?我怎样才能修好它


谢谢大家:)

GridView实际上不支持具有不同高度的项目,因此您可以执行以下操作:

  • 让你所有的物品都有相同的高度:在这种情况下,它是相当高的 简单地说,将android:lines=“2”添加到体育节目标题中,使所有 你的头衔有两行高
  • 使用一个定制的android交错网格视图,比如(谷歌的第一次成功)
  • 我相信一个布局错乱的回收站管理员可以做到这一点 你也一样

我认为这与图片下的文字量有关。如果你把它缩成一行,这还会发生吗?@Thealon哦。。将所有文本缩减为一行后,该错误已修复!但是我必须使用所有这些文本。。隐马尔可夫模型。。我不知道如何解决。@Stella如果字符串超过一行,可以更改字体大小吗?@Thealon谢谢Thealon,这是一个很好的解决方案。我会尽可能地减小字体大小,但是,有些文本有两行。。而且这个尺寸看起来并不是那么小。T-T()@Stella是的,你可以做到:“Bla-Bla\n”我想这会奏效。我使用第一种方法,它成功地运行了。非常感谢:)