Search code examples
androidimageandroid-imageview

Display an image with height 'matchparent' and also keep the aspectratio


I want to display an image in Imageview with full height and also keep the aspect ratio of the image. To view the remaining part of the image, I want horizontal scrolling on that image. Please share the idea behind it?

enter image description hereenter image description here


Solution

  • As mentioned by ResolutioN, adjustViewBounds does the trick, but fitXY is not necessary. Just wrap your ImageView inside a HorizontalScrollView

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