而使用通用图像装载机在Android的网格视图滚动图像重复 [英] Repetition of image while scrolling in Android grid view using Universal Image Loader

查看:151
本文介绍了而使用通用图像装载机在Android的网格视图滚动图像重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图加载使用上的GridView通用图像装载机使用下面的code从互联网上的图片。

I am trying to load images from the Internet using Universal Image Loader on a gridview using the below code.

public View getView(int position, View converView, ViewGroup parent) {
        Log.v("Description", "Description is " + position);
        ViewHolder mVHolder;
        if (converView == null) {
            LayoutInflater vi = (LayoutInflater) conted.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            converView = vi.inflate(R.layout.customgrid, null);
            mVHolder = new ViewHolder();
            mVHolder.mImageView = (ImageView) converView
                    .findViewById(R.id.imgview);
            mVHolder.mTextView1 = (TextView) converView
                    .findViewById(R.id.textView1);
            mVHolder.mTextView2 = (TextView) converView
                    .findViewById(R.id.textView2);
            mVHolder.mTextView3 = (TextView) converView
                    .findViewById(R.id.textView3);

            converView.setTag(mVHolder);
        } else {
            mVHolder = (ViewHolder) converView.getTag();
        }
        // mVHolder.mImageView.setImageResource(mThumbIds[position]);
        // mVHolder.mImageView.setImageDrawable(LoadImageFromURL(
        // mThumbIds[position]));
        imageLoader.displayImage(mThumbIds[position],mVHolder.mImageView,options, animationListener);
        Log.v("Names",NAMES[position] + STATES[position] + CONSTITUENCY[position]);
        mVHolder.mTextView1.setText(NAMES[position]);
        mVHolder.mTextView2.setText(STATES[position]);
        mVHolder.mTextView3.setText(CONSTITUENCY[position]);
        return converView;
    }

然而,当我在列表向下滚动,第一行的第一图像似乎在大多数电网重复。它不留所有的时间 - 它一段时间后变回原始图像。我的问题是,这是对通用图像装载机的GridView控件或图像加载?

However, when I scroll down in the list, the first image of the first row seems to repeat in most of the grids. It does not stay all the time - it changes back to the original image after a while. My question is, is this a issue with view inflation on gridview or image loading of Universal Image Loader?

推荐答案

我觉得你的问题是,你是不是设置了 resetViewBeforeLoading()方法 DisplayImageOptions 是这样的: -

I think your problem is that you are not setting the resetViewBeforeLoading() method for DisplayImageOptions like this:-

     DisplayImageOptions options = new DisplayImageOptions.Builder()
    .showStubImage(R.drawable.stub_image)
    .showImageForEmptyUri(R.drawable.image_for_empty_url)
 ---->   .resetViewBeforeLoading(true)<----very important for recycling views
    .cacheInMemory()
    .cacheOnDisc()
    .imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2) // default
    .bitmapConfig(Bitmap.Config.ARGB_8888) // default
    .delayBeforeLoading(1000)
    .displayer(new SimpleBitmapDisplayer()) // default
    .build();

然后再应用此DisplayImageOptions。

and then apply this DisplayImageOptions.

        imageLoader.displayImage(mThumbIds[position],mVHolder.mImageView,options,                   animationListener);

这篇关于而使用通用图像装载机在Android的网格视图滚动图像重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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