Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android image view size does not scale with image

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?

like image 658
Fumbles Avatar asked Jun 11 '11 04:06

Fumbles


People also ask

What is adjust view bounds?

android:adjustViewBounds—If set to true, the attribute adjusts the bounds of the ImageView control to maintain the aspect ratio of the image displayed through it. android:resizeMode—The resizeMode attribute is used to make a control resizable so we can resize it horizontally, vertically, or around both axes.

How do you show the full size image in pop up when clicking the picture on android?

How to show the full size image in popup on clicking the image in android. Below is the code that will show the full size image in a dialog box popup without defining layout xml file . int a=v. getId(); intiger "a" will have the value equal to profile_pic if we touched on profile_pic imageview else we will get pro id .

How do you change the size of a picture on android?

Tap the image you want to adjust. You can adjust the size of an image or rotate it: Resize: Touch and drag the squares along the edges. Rotate: Touch and drag the circle attached to the image.


1 Answers

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

like image 61
Pikaling Avatar answered Oct 20 '22 18:10

Pikaling