Question

I am trying to use 'Universal Image Loader' to load images inside of my ListView. My code looks like that:

public View getView(int position, View convertView, ViewGroup parent) 
if (convertView == null) {
        convertView = mInflater.inflate(R.layout.offers_list_adapter, null);

        holder = new ViewHolder();
        holder.mIvImage = (ImageView) convertView
                .findViewById(R.id.ivImage);
        holder.mTxtName = (TextView) convertView.findViewById(R.id.txtName);
        holder.mTxtCategoryName = (TextView) convertView
                .findViewById(R.id.txtCategoryName);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }

I have one rule:

If this item in my list is special one, I have to change my ImageView's params (e.g. special item has imageView bigger than normal).

So in my code I do that:

if (holder.isSpecial) {
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, 50);
            layoutParams.gravity = Gravity.CENTER_HORIZONTAL;
            holder.mIvImage.setLayoutParams(layoutParams);
}

After I change my params, I call the 'Universal Image Loader' library as usual:

imageLoader.displayImage(holder.url, holder.mIvImage); 

But when the library execute in my UI thread to put the image in my ImageView, my ImageView is not at center and the size is wrong. My changes that I made because this item is special are not applied.

I have my own ImageDownloader and when I use it the ImageView load with the new params correctly (center and new size), but in many other points my own class is not so good as this library.

Anyone have any idea what might be happening?

Thanks in advance,

Cheers!


My 'Universal Image Loader' configuration:

DisplayImageOptions options = new DisplayImageOptions.Builder()
                .cacheInMemory().cacheOnDisc()
                .imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2)
                .displayer(new RoundedBitmapDisplayer(0)).build();


        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
                mContext)
                .memoryCacheExtraOptions(480, 800)
                .discCacheExtraOptions(480, 800, CompressFormat.JPEG, 75)
                .threadPoolSize(3)
                .threadPriority(Thread.NORM_PRIORITY - 1)
                .denyCacheImageMultipleSizesInMemory()
                .offOutOfMemoryHandling()
                .memoryCache(new UsingFreqLimitedMemoryCache(2 * 1024 * 1024))
                .discCache(new UnlimitedDiscCache(file))
                .discCacheFileNameGenerator(new HashCodeFileNameGenerator())
                .imageDownloader(
                        new URLConnectionImageDownloader(5 * 1000, 20 * 1000))
                .defaultDisplayImageOptions(DisplayImageOptions.createSimple())
                .enableLogging().defaultDisplayImageOptions(options).build();

        imageLoader.init(config);
Was it helpful?

Solution

You have copy-pasted configuration from GitHub Readme. This config (on GitHub) just shows ALL possible options, but you SHOULD NOT call all of them.

You should look into example project (UniversalImageLoaderExample) to see right way of tuning and using UIL.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top