Search code examples
androidgridviewimageviewuniversal-image-loader

UIL image display in the center of imageView in GridView


This is what my android project interface looks like. As you can see, the images are all sticking to the left-hand-side. I tried in XML gridView, imageView putting layout_gravity="center", scaleType="center", adjustviewbounds="true" but none seem to work. I just used this UIL 2 hours ago. I'm new to UIL.

My UIL defaultoption :

DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
            .cacheOnDisc(true).cacheInMemory(true)
            .imageScaleType(ImageScaleType.EXACTLY)
            .displayer(new FadeInBitmapDisplayer(300)).build();

My XML GridView:

<?xml version="1.0" encoding="utf-8"?>
<GridView
    android:id="@+id/gridView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:horizontalSpacing="1dp"
    android:verticalSpacing="1dp"
    android:numColumns="3"
    android:gravity="center"
    xmlns:android="http://schemas.android.com/apk/res/android">

</GridView>

imageView:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
    android:id="@+id/ivGrid_images"
    android:layout_width="wrap_content"
    android:layout_height="100dp"
    android:scaleType="centerInside"
    android:layout_gravity="center"/>

</LinearLayout>

enter image description here


Solution

  • Change the

    .imageScaleType(ImageScaleType.EXACTLY) 
    

    to

    .imageScaleType(ImageScaleType.NONE)
    

    Finally I got the answer after trying to change all to layout_gravity="center".