7

I have the following android layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mainTopLevel"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
>
    <ImageView
        android:id="@+id/orbitImage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:scaleType="fitStart"
        android:src="@drawable/earthorbit"
        android:padding="0dp"
        android:background="@android:color/white"
    />
    <TextView
        android:id="@+id/positionDesc"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:minHeight="40dp"
        android:layout_below="@id/orbitImage"
        android:text="should appear below image"
   />
</RelativeLayout>

The image scales down quite a bit, but since the aspect ratio is maintained, it only takes up the top half of the screen.

The problem is that the image view itself has the original height, which takes the entire screen and the text never shows up.

(So the original image is about 620 X 430, the scaled image is about 250 X 200, but the image view is about 250 X 430)

Is there a way to get the size of the image view to exactly match the scaled size of the image?

Fumbles
  • 71
  • 1
  • 2

2 Answers2

11

It looks similar to this problem: Android ImageView size not scaling with source image, to which to the solution was to add android:adjustViewBounds="true" to the ImageView

Community
  • 1
  • 1
Pikaling
  • 8,282
  • 3
  • 27
  • 44
  • You are a savior. I wish I could vote you up 1000x. Was really starting to get frustrated with this. If anyone else is looking, it works for gridView as well. – RiddlerDev Nov 25 '12 at 04:46
0

Since the sizes are fixed by the image file in resources, then there is no reason why you should not be able to fix the height on your ImageView: android:layout_height="200dp"

Aleadam
  • 40,203
  • 9
  • 86
  • 108