android imageView scale

249 Views Asked by At

I have an ImageView which is populated from database (the image comes from database). in the database i have images both portrait and landscape!! how can i adjust the imageView to scale it self according to the image width and height. I have tried many ways but no result! any help please!!!!

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <HorizontalScrollView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        >

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/slideshow"
        android:orientation="horizontal"
        android:padding="0dp"
        >

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="300dp"
            android:layout_marginRight="5dp"
            android:id="@+id/slide1"
            android:src="@drawable/ddd"
            />
1

There are 1 best solutions below

1
On BEST ANSWER

Try this code. adjustViewBounds attribute makes the ImageView the same size as image that you put in it.

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true" />

If you need specific width or height change the wrap_content value.