如何避免闪烁,同时更新GridView的? [英] How to avoid flickering while updating gridview?

查看:1822
本文介绍了如何避免闪烁,同时更新GridView的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个GridView。我可是从10个图像阵列显示图像。 1分钟后我加入5更多的图片。要我用下面的code更新GridView控件。

I have a gridview. Im displaying images from the array of 10 images. After 1 minute i'm adding 5 more images. To update the gridview i'm using the following code.

aImgAdapterL.notifyDataSetChanged();  

aImgAdapterL 是我ImgaeAdapter。新的图像得到显示。
我的问题是更新的GridView 1闪烁或闪烁的图像updation期间发生的时候。是否有可能隐藏闪烁?

aImgAdapterL is my ImgaeAdapter. The new images are getting displayed.
My problem is when updating the gridview one flickering or blinking happening during the image updation. Is it possible to hide that flickering?

推荐答案

我有同样的问题,能够解决这样的:

I had the same issue and was able to solve it like this:

事实上,这是因为我的 ListAdapter 这没有处理得当的情况下,当整个列表被刷新。如果是这样,你想要做的就是保持项目已经什么显示在屏幕上按原样。

In fact it was due to my ListAdapter which didn't managed properly the case when the whole list is refreshed. If so, what you want to do is keeping the items already displayed on the screen as-is.

要做到这一点,在方法 getView 当你得到一个回收项目的适配器,你必须检查,如果它不是已经要显示一个。如果是这样的话,就直接返回了。

To do so, in the method getView of the Adapter when you get a recycled item, you must check if it's not already the one you want to display. If it's the case, just return it directly.

@Override
public View getView(int position, View convertView, ViewGroup container) {
    ImageView imageView;
    String src = this.getItem(position).getSrcThumbnail();
    if (convertView == null) {
        imageView = new ImageView(getContext());
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);

        int height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 120, getResources().getDisplayMetrics());

        imageView.setLayoutParams(new GridView.LayoutParams(GridView.LayoutParams.MATCH_PARENT, height));

    } else {
        imageView = (ImageView) convertView;

        // When you get a recycled item, check if it's not already the one you want to display.
        String newSrc = (String) imageView.getTag();

        if(newSrc.equals(src)){
            // If so, return it directly.
            return imageView;
        }
    }

    loadBitmap(this.getItem(position).getSrcThumbnail(), imageView);

    // Here you set the unique tag that allow to identify this item.
    imageView.setTag(src);

    return imageView;
}

这篇关于如何避免闪烁,同时更新GridView的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆