1

I have already looked at this thread: ImageView adjustViewBounds not working but it doesn't apply to my situation.

Essentially, adjustViewBounds isn't working. Let's assume the following:

square_icon => 1000x1000
rectangle_icon => 400x100
device height => 1000

So what I want to happen is a vertical stacking of four icons with the following dimensions:

square_icon = 400x400
rectangle_icon = 400x100
square_icon = 400x400
rectangle_icon = 400x100

But what's happening is that the square_icon isn't taking up all the space it can... and the rectangle_icon is more like 400x200 instead of 400x100? The image isn't being scaled with an incorrect aspect ratio, there is just blank space added to the view (scalingType determines whether the space is at the top, bottom, or both)

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

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="0dip"
        android:layout_weight="1"
        android:adjustViewBounds="true"
        android:src="@drawable/square_icon" />

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:src="@drawable/rectangle_icon" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="0dip"
        android:layout_weight="1"
        android:adjustViewBounds="true"
        android:src="@drawable/square_icon" />

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:src="@drawable/rectangle_icon" />

</LinearLayout>
Community
  • 1
  • 1
slaman
  • 49
  • 1
  • 3
  • As a follow-up, if I take out the android:adjustViewBounds="true" line from the two square_icon ImageViews, then the height of the rectangle_icon ImageViews is correct... however, the width of the square_icon becomes incorrect (it turns into a rectangle) – slaman Sep 14 '12 at 06:29
  • I think I answered my own question... the linked thread actually does apply to this situation, because my images are actually smaller than what I'm trying to scale them up to be! Apparently you cannot use adjustViewBounds when scaling up... – slaman Sep 14 '12 at 06:39
  • Increased the sizes of all images... and still facing the same problem. I'm at a loss - any ideas? – slaman Sep 14 '12 at 06:49
  • Removing android:adjustViewBounds="true" from the third ImageView now makes it work for large and xlarge screens... small and normal screens aren't working still. Must be a bug? There is no logic in it working only on certain screens? – slaman Sep 14 '12 at 06:56

1 Answers1

1

I solved this, for those interested, by explicitly specifying a height of the rectangle_icon by using weights... Assigned a weight of 4 to each square_icon, and a weight of 1 to each rectangle_icon. Took me forever, but I finally figured it out!

slaman
  • 49
  • 1
  • 3
  • you also need layout_height=0px for each ImageView, so the entire vertical space is split fair among them according to the specified layout_weight.. – aleb Aug 01 '13 at 11:19