Question

I would like to show a photo from my phone in an ImageView. This photo is supposed to be shown in it's original aspect ratio. So it should fill up the whole width, but only use as much height as it needs due to it's ratio. In short: I want to show a photo in an imageview without scaling.

How can I do that? Right now I am using this layout. The problem is that it always scales the photo to fill up the whole screen.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/root" 
    android:orientation="vertical"
    android:background="@android:color/black">

<ImageView
    android:id="@+id/image"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:adjustViewBounds="true"
    android:scaleType="center" />

</LinearLayout>
Was it helpful?

Solution

You can use ScaleType CENTER_INSIDE for this purpose. For more detail go through link. Android ImageView ScaleType

OTHER TIPS

Try put image in drawable-nodpi folder and set wrap_parent for width and height in ImageView and set link to image in src

Try to set width to match parent, height to wrap content and to adjust view bounds:

    <ImageView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true"
    android:src="@drawable/drawable"/>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top