【问题标题】:Loading the correct Image in List View在列表视图中加载正确的图像
【发布时间】:2014-02-19 06:48:11
【问题描述】:

我正在制作一个在列表视图中显示来自 url 的图像的应用程序。我使用异步任务来获取图像并将其放入图像视图中。我目前拥有的方式是在 getview 方法中调用 asynctask。 do in background 部分从 url 获取图像。我遇到的问题是当我滚动到列表视图中的一个元素时,最初存在错误的图像,但正确的图像很快加载。为什么会这样?

xml

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

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scaleType="fitStart"
            android:src="@drawable/ic_launcher" />

</LinearLayout>

【问题讨论】:

  • 请发布您的列表行布局?

标签: android android-asynctask android-imageview


【解决方案1】:

确保在声明 ImageView 后立即将其设置为 null。如果不知道图像是什么就很难判断,但 ListView 可能正在重用旧图像。参考如下:

wrong images are displaying first and then correct images are displaying during scrolling of listview

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-07
    相关资源
    最近更新 更多