Search code examples
androidimageviewuniversal-image-loader

how to use Universal-Image-Loader to load picture that the size not changed


I use the framework Universal-Image-Loader to load pictures from the Internet and the imageview is created dynamically before the practice ,but I am not satisfacted by it's result . the pictures which are showed in my app is too small not original size . I don't want to change the size of picture . So I use WebView to load by image's url then the pictures are perfect displayed ,however the app will seize up and stopped when the pictures are many.please help me ,how to set the configuration of it ? maybe the imageview should be reseted?

there are my codes:

if(url!=null){
            ImageView imageView = new ImageView(activity); 
            imageView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
            imageView.setMinimumHeight(20);
            imageView.setImageResource(R.drawable.loading);  

           // bad method
          //  WebView webView=new WebView(activity);
           // webView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
           // group.addView(webView);
           // webView.loadUrl(url);
          //  webView.setWebViewClient(new WebViewClient(){

            //  @Override
            //  public boolean shouldOverrideUrlLoading(WebView view,
            //          String url) {
            //      // TODO Auto-generated method stub
            //      view.loadUrl(url);
            //      return true;
            //  }
           //   
           // });

            ImageLoader.getInstance().displayImage(url,imageView,options);
            group.addView(imageView);

Solution

  • // IN Display image option set image scale type exactly 
    // below code help you in this image will be download according to imageView       //width height
    
     public static void initImageLoader(Context context) {
            DisplayImageOptions options = new DisplayImageOptions.Builder()
                    .showImageOnLoading(R.drawable.picture)
                    .showImageForEmptyUri(R.drawable.picture)
                    .showImageOnFail(R.drawable.picture)
                    .cacheInMemory(true)
                    .cacheOnDisk(true)
                    .considerExifParams(true)
                    .imageScaleType(ImageScaleType.EXACTLY)
                    .build();
    
            ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
                    .threadPriority(Thread.NORM_PRIORITY - 2)
                    .denyCacheImageMultipleSizesInMemory()
                    .discCacheFileNameGenerator(new Md5FileNameGenerator())
                    .tasksProcessingOrder(QueueProcessingType.LIFO)
                    .defaultDisplayImageOptions(options)
                    .build();
            // Initialize ImageLoader with configuration.
            ImageLoader.getInstance().init(config);
        }