Search code examples
androidxmlimageviewscale

Android: xml image scaling not increasing image size enough


I'm working on an app with a custom dialog. Inside of that dialog, there is an image that i set in my code depending on which item in a list view is clicked. Everything in the dialog works. The image shows up along with the buttons and text. However the images I am using remain much smaller than I'd like. I tried to follow this tutorial, but it won't scale the images up past a point. It will scale them down, but not up. I have tried various methods to fix this including different android:scaleType="", but to no avail. Any help would be greatly appreciated. I would like to avoid setting the size individually because i have over 400 images, I would like them to be set once and done in xml.

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

<ImageView android:id="@+id/ImageView01"
 android:contentDescription="@string/desc"
 android:saveEnabled="true"
 android:adjustViewBounds="true"
 android:scaleType="fitXY"
 android:maxWidth="375dp"  
 android:maxHeight="375dp"
 android:layout_width="wrap_content" android:layout_height="wrap_content"
 android:layout_centerHorizontal="true" />

 <ScrollView android:id="@+id/ScrollView01"
 android:layout_width="wrap_content" android:layout_below="@+id/ImageView01"
 android:layout_height="wrap_content">

 <TextView android:id="@+id/TextView01"
 android:layout_width="wrap_content" android:layout_height="wrap_content"
 android:paddingLeft="5dp" />

 </ScrollView>

 <Button
 android:id="@+id/Button01"
 android:layout_width="150dp"
 android:layout_height="50dp"
 android:layout_alignParentRight="true"
 android:layout_below="@+id/ScrollView01"
 android:background="@drawable/border"
 android:text="@string/cancel"
 android:textColor="#ffffff" />

 <Button
 android:id="@+id/Button02"
 android:layout_width="150dp"
 android:layout_height="50dp"
 android:layout_below="@+id/ScrollView01"
 android:background="@drawable/border"
 android:text="@string/copy"
 android:textColor="#ffffff" />

 </RelativeLayout>

Solution

  • Put your images in the /res/drawable-nodpi folder (or change the code accordingly and place them in the assets/ folder).

    Remove those images from the other drawable/ folders. Tell us their dimensions. Test them on different screens in different orientations. Since these images will be taking the entire width of the screen, you may have to tailor your layout for the different size buckets, but I doubt you'll need to do that for the different density buckets.