1

是的,我看过其他问题,但那里的答案对我没有帮助。

我的应用程序从 Web 加载的图像放置在GridView. 这是和的getView代码onScrollStateChanged

@Override
public void onScrollStateChanged(AbsListView absListView, int scrollState) {

    switch(scrollState) {
        case SCROLL_STATE_FLING :
        case SCROLL_STATE_TOUCH_SCROLL :
            downloader.stopAll();
            adapter.removeExecutor(productCategoriesExecutor);
        break;

        case SCROLL_STATE_IDLE :
            loadProductsChunk();
        break;
    }
}

@Override
public View getView(int i, View view, ViewGroup viewGroup) {
    ProductView productView = (ProductView)view;

    if(productView == null) {
        productView = new ProductView(context, downloader);
        productView.setLayoutParams(new GridView.LayoutParams(columnWidth, rowHeight));
    }

    JSONObject product = getItem(i);

    if(product != null) {
        try {
            Log.i("ololo", String.format("thm: %d ", i) + product.getString("thumbnail"));

            productView.setNewPrice(product.getInt("price"));
            productView.setOldPrice(product.getInt("oldPrice"));
            productView.showThumbnail(product.getString("thumbnail"));
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    else {
        productView.setNewPrice(0);
        productView.setOldPrice(0);
        productView.showThumbnail(null);
    }
    return productView;
}

还有GridView

<GridView
        android:id="@+id/productsGrid"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:verticalSpacing="@dimen/products_list_grid_spacing"
        android:horizontalSpacing="@dimen/products_list_grid_spacing"
        android:stretchMode="columnWidth"
        android:scrollingCache="false"
        android:alwaysDrawnWithCache="false"
    />

如您所见,ProductView接收链接然后加载(或从缓存中获取)图像。刷新是在哪里执行,也不是在触摸,现在滚动都不是活动的。

public void displayRemoteImage(RemoteImage remoteImage) {
    if(this.remoteImage != null) {
        Log.i("ololo", this.remoteImage.getUrl() + remoteImage.getUrl());
    }

    if(this.remoteImage == null || !this.remoteImage.getUrl().equals(remoteImage.getUrl())) {
        this.remoteImage = remoteImage;
        this.remoteImage.setDelegate(this);
    }
}

好的

但是,如果我滚动到任何地方并返回(使用其他图片),它们会闪烁!
好吧,这不是什么大问题。
让我们再加载一行

在此处输入图像描述

搞什么鬼??
而且-是的-如果我滚动到任何地方并返回,就会有需要的图片(并且没有重新加载)。

好吧,也许我们是失败者并且搞砸了我们的下载?让我们简单地刷新图片:

在此处输入图像描述

哈哈。你们太无聊了,我回家了。

以下是更新日志:

06-25 17:26:09.759: INFO/ololo(6613): viewId: 0, should show the link: http://mysite//img/products/3/3031/3031thm.jpg
06-25 17:26:09.779: INFO/ololo(6613): original link: http://mysite//img/products/41/41230/41230thm.jpg; should show: http://mysite//img/products/3/3031/3031thm.jpg
06-25 17:26:09.779: INFO/ololo(6613): viewId: 0, should show the link: http://mysite//img/products/3/3031/3031thm.jpg
06-25 17:26:09.859: INFO/ololo(6613): original link: http://mysite//img/products/3/3031/3031thm.jpg; should show: http://mysite//img/products/3/3031/3031thm.jpg
06-25 17:26:09.869: INFO/ololo(6613): viewId: 0, should show the link: http://mysite//img/products/3/3031/3031thm.jpg
06-25 17:26:09.889: INFO/ololo(6613): original link: http://mysite//img/products/3/3031/3031thm.jpg; should show: http://mysite//img/products/3/3031/3031thm.jpg
06-25 17:26:09.889: INFO/ololo(6613): viewId: 0, should show the link: http://mysite//img/products/3/3031/3031thm.jpg
06-25 17:26:09.909: INFO/ololo(6613): original link: http://mysite//img/products/40/40963/40963thm.jpg; should show: http://mysite//img/products/3/3031/3031thm.jpg
06-25 17:26:09.919: INFO/ololo(6613): viewId: 1, should show the link: http://mysite//img/products/40/40748/40748thm.jpg
06-25 17:26:09.939: INFO/ololo(6613): original link: http://mysite//img/products/40/40940/40940thm.jpg; should show: http://mysite//img/products/40/40748/40748thm.jpg
06-25 17:26:09.939: INFO/ololo(6613): viewId: 2, should show the link: http://mysite//img/products/40/40771/40771thm.jpg
06-25 17:26:09.999: INFO/ololo(6613): original link: http://mysite//img/products/40/40934/40934thm.jpg; should show: http://mysite//img/products/40/40771/40771thm.jpg
06-25 17:26:09.999: INFO/ololo(6613): viewId: 3, should show the link: http://mysite//img/products/40/40790/40790thm.jpg
06-25 17:26:10.009: INFO/ololo(6613): original link: http://mysite//img/products/40/40914/40914thm.jpg; should show: http://mysite//img/products/40/40790/40790thm.jpg
06-25 17:26:10.009: INFO/ololo(6613): viewId: 4, should show the link: http://mysite//img/products/40/40913/40913thm.jpg
06-25 17:26:10.029: INFO/ololo(6613): original link: http://mysite//img/products/40/40913/40913thm.jpg; should show: http://mysite//img/products/40/40913/40913thm.jpg
06-25 17:26:10.029: INFO/ololo(6613): viewId: 5, should show the link: http://mysite//img/products/40/40914/40914thm.jpg
06-25 17:26:10.049: INFO/ololo(6613): original link: http://mysite//img/products/40/40790/40790thm.jpg; should show: http://mysite//img/products/40/40914/40914thm.jpg
06-25 17:26:10.049: INFO/ololo(6613): viewId: 6, should show the link: http://mysite//img/products/40/40934/40934thm.jpg
06-25 17:26:10.069: INFO/ololo(6613): original link: http://mysite//img/products/40/40771/40771thm.jpg; should show: http://mysite//img/products/40/40934/40934thm.jpg
06-25 17:26:10.069: INFO/ololo(6613): viewId: 7, should show the link: http://mysite//img/products/40/40940/40940thm.jpg
06-25 17:26:10.089: INFO/ololo(6613): original link: http://mysite//img/products/40/40748/40748thm.jpg; should show: http://mysite//img/products/40/40940/40940thm.jpg
06-25 17:26:10.099: INFO/ololo(6613): viewId: 8, should show the link: http://mysite//img/products/40/40963/40963thm.jpg
06-25 17:26:10.159: INFO/ololo(6613): original link: http://mysite//img/products/3/3031/3031thm.jpg; should show: http://mysite//img/products/40/40963/40963thm.jpg
06-25 17:26:10.330: INFO/ololo(6613): viewId: 0, should show the link: http://mysite//img/products/3/3031/3031thm.jpg
06-25 17:26:10.340: INFO/ololo(6613): original link: http://mysite//img/products/3/3031/3031thm.jpg; should show: http://mysite//img/products/3/3031/3031thm.jpg
06-25 17:26:10.340: INFO/ololo(6613): viewId: 0, should show the link: http://mysite//img/products/3/3031/3031thm.jpg
06-25 17:26:10.390: INFO/ololo(6613): original link: http://mysite//img/products/3/3031/3031thm.jpg; should show: http://mysite//img/products/3/3031/3031thm.jpg
06-25 17:26:10.390: INFO/ololo(6613): viewId: 0, should show the link: http://mysite//img/products/3/3031/3031thm.jpg
06-25 17:26:10.410: INFO/ololo(6613): original link: http://mysite//img/products/3/3031/3031thm.jpg; should show: http://mysite//img/products/3/3031/3031thm.jpg

更新

这在 HTC Explorer (2.3.3) 和 HTC Nexus One (2.3.6) 上发生,但在三星 Galaxy Tab 10.1 (3.2) 上没有发生。

4

2 回答 2

0

它来自于内心的实现BaseAdapter。似乎它将视图存储在堆栈或类似的东西中,因此在屏幕更新后它以相反的顺序放置视图。解决方案是尽可能加快数据刷新速度。请记住,您不应该使用异步数据刷新:它会导致闪烁。

于 2012-07-02T19:58:08.040 回答
0

使用 ViewHolder 模式。和一个下载和缓存的 ImageManager。

于 2012-11-06T04:18:42.980 回答