【问题标题】:GridView cannot show imageGridView 无法显示图像
【发布时间】:2011-05-10 01:27:34
【问题描述】:

我得到所有应用程序的图标,并在 GridView 中显示这些图标。 GridView 可以很好地显示它们,但是当我将 GridView 快速向下滑动时,有时 GridView 缺少两个图标。这种情况不常出现,能否给点建议。

编辑:之前有人问过这个问题,但没有答案。 Scrolling issues with GridView in Android

【问题讨论】:

    标签: android android-gridview


    【解决方案1】:

    在我的情况下,我已经在使用这些 XML 显示图像和文本的 GridView 适配器中解决了这个问题:

    <!--  <LinearLayout android:layout_width="fill_parent"  android:layout_height="18dip"  /> -->
        <LinearLayout
                android:id="@+id/iconBackgroundLinear"
                android:layout_width="54dip"
                android:layout_height="57dip"
                android:gravity="center">
    
            <ImageView
                    android:id="@+id/app_icon"
                    android:layout_width="45dip"
                    android:layout_height="45dip"
                    android:adjustViewBounds="false"
                    />
        </LinearLayout>
    
        <TextView
                android:id="@+id/app_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingTop="2dip"
                android:gravity="center_horizontal"
                android:lines="2"
                />
        </LinearLayout>
    

    关键是 android:lines="2",当我使用 android:maxline="2" 时,可能会出现上述错误。

    【讨论】:

    • 我认为你很幸运。我有同样的问题,没有任何文本,有一个带有普通 LinearLayout 元素和 Shape 背景的 ViewSwitcher。似乎是一个奇怪的 Android 错误...
    • 虽然这确实为我解决了问题,但它暗示他们在 GridView 中存在更根本的问题。也许它不喜欢可变高度条目?
    • 我认为只保持 android:lines 值相同,也许可以重温你的问题
    • 它也对我有用。我也有一个带有 ImageView 和 TextView 的类似结构的 gridview,文本的长度完全随机。感谢您的回答。
    • 没有解决问题,因此解决方案与互联网所能告知的一样糟糕。别听这些狗屁话。
    【解决方案2】:

    我已经解决了这个问题,替换为

    <LinearLayout
        android:orientation="horizontal"
        android:layout_marginTop="@dimen/big_margin"
        android:layout_width="match_parent"
        android:layout_marginLeft="@dimen/big_margin"
        android:layout_height="wrap_content">
    

    <LinearLayout
        android:orientation="horizontal"
        android:layout_marginTop="@dimen/big_margin"
        android:layout_width="match_parent"
        android:layout_marginLeft="@dimen/big_margin"
        android:layout_height="@dimen/workoutlist_itemheight">
    

    但我真的不知道我的问题是如何解决的。

    谢谢

    【讨论】:

      猜你喜欢
      • 2021-09-04
      • 2012-03-10
      • 2011-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-18
      • 1970-01-01
      相关资源
      最近更新 更多