Search code examples
androidgridviewuniversal-image-loader

imageview in gridview wrong size, after replacing loading placeholder


I'm using gridview, to show a 2 column list of images.

I am using universal image loader to get the images from database, which works great, but as soon as the image is loaded, and the "loading image" placeholder is replaced, the size gets shrinked down to the images actual size, and does not fill the cell properly.

The placeholder images are scaled up properly, to fill available width, and wrap the height. All images are the same size, and need to be scaled up, or down, depending on the screen size.

Here is the list item layout(updated, I have a textview there too, which I think is irrelevant, but who knows..):

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ImageView
        android:id="@+id/grid_gallery_item_imageView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerInParent="true"
        android:adjustViewBounds="true"
        android:scaleType="fitCenter"
        android:src="@drawable/loading_image" />

    <TextView
        android:id="@+id/grid_gallery_item_textView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/grid_gallery_item_imageView1"
        android:background="#50000000"
        android:ellipsize="end"
        android:gravity="center_vertical"
        android:maxLines="3"
        android:padding="8dp"
        android:text="Bacon ipsum."
        android:textColor="#ffffff"
        android:textSize="20sp" />

</RelativeLayout>

Here is my gridview:

 <GridView
        android:id="@+id/grid_gallery_layout_gridView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:numColumns="2"
        android:stretchMode="columnWidth">

In my gridview adapter, I just use this to load the images:

imageLoader.displayImage("db://" + item.imageId, holder.imageView, options);

the options:

options = new DisplayImageOptions.Builder().bitmapConfig(Bitmap.Config.RGB_565).showStubImage(R.drawable.loading_image)
        .displayer(new FadeInBitmapDisplayer(Constants.GRIDVIEW_IMAGE_FADEIN_TIME)).build();

Here is a screenshot, of the problem:

enter image description here

The loaded images should be the same size, as the placeholder images.

Any ideas, why loading the images might screw up the sizing of the imageviews?

Edit: down scaling actually works fine, it's up scaling that is screwed up. For example, on a smaller screen, the images are correct size.


Solution

  • It seems that I have solved the problem. Apperantly ImageView does not scale up images properly, if it is inside a gridview.

    This code works for me perfectly: link