Search code examples
androidxmluniversal-image-loader

Universal-Image-Loader not following layout_weight


I am using Universal Image Loader to grab some images and display them in a listview. I am having trouble getting the layout looking right. I want the image to use no more than 25% of the width, and this looks fine in the Graphical Layout view in Eclipse, but when the image is downloaded it is displayed full size which is too large. I was hoping to avoid using maxwidth as I dont know what the full width will be.

This is my layout xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:padding="10dp"
android:weightSum="100" >

<ImageView
    android:id="@+id/imgIcon"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:layout_gravity="center_vertical"
    android:layout_weight="25"
    android:contentDescription="@string/offerImage"
    android:paddingRight="10dip"
    android:src="@drawable/ic_launcher" />

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="75"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/txtTitle"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="5dp"
        android:layout_marginTop="5dp"
        android:text="tempString"
        android:textColor="#ffffffff"
        android:textSize="18sp" />

    <TextView
        android:id="@+id/txtRetailer"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Business name"
        android:textColor="#ffffffff"
        android:textSize="16sp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/txtDistance"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:text="99.99 miles"
        android:textColor="#ffffffff"
        android:textSize="12sp"
        android:textStyle="bold" />
</LinearLayout>


Solution

  • The solution is to set layout_width value to 0dip for both ImageView and LinearLayout. layout_weight works only for unused space, so in case image is too large there is no any free space.