Search code examples
androidandroid-imageviewuniversal-image-loader

Remove spacing between images UIL


I'm trying to inflate several imageviews in a horizontal scroll view using Universal image loader and following code

for (int i = 0; i < received_params.length; i++) { //received_params ARRAY CONTAING URLs
            final ImageView image = new ImageView(this);
            LinearLayout.LayoutParams params = null;
            params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
            image.setLayoutParams(params);

            imageLoader.displayImage(received_params[i], image, options);   
            scrnshts_ll.addView(image); //scrnshts_ll is the object of Linear Layout image_view_ll
        }

and my horizontal scroll view is

 <HorizontalScrollView
android:id="@+id/image_view_hll"
android:layout_width="fill_parent"
android:layout_height="250dp"
android:background="@color/overlay_bg"
android:padding="5dp" >

<LinearLayout
android:id="@+id/image_view_ll"
android:layout_width="wrap_content"
android:layout_height="match_parent"
 android:orientation="horizontal" >
</LinearLayout>

now my problem can clearly be seen in attached image, in which there is a spacing b/w every image. I want to remove gaps b/w images. How to do it.enter image description here


Solution

  • imageLoader.loadImage(received_params[i], new ImageLoadingListener() {
    
                    @Override
                    public void onLoadingStarted(String imageUri, View view) {
    
                    }
    
                    @Override
                    public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
    
                    }
    
                    @Override
                    public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                        int width = loadedImage.getWidth();
                        ImageView image = new ImageView(AppDetailsActivity.this);
                        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( (int)(width), LinearLayout.LayoutParams.MATCH_PARENT);
                        }
    
                        params.setMargins(10, 0, 10, 0);
                        image.setLayoutParams(params);
                        image.setScaleType(ScaleType.FIT_XY);
                        image.setImageBitmap(loadedImage);
                        scrnshts_ll.addView(image);
                    }
    
                    @Override
                    public void onLoadingCancelled(String imageUri, View view) {
    
                    }
                });