0
votes

I am trying to resize an image by keeping the aspect ratio. It should be just large enough to fill the screen width and if necessary some of the image should be off-screen.

here is a picture of what I want

I tried

android:adjustViewBounds

but when the image is larger than screen it fits image into imageView and not filling the width.

And I also don't want to use :

android:scaleType="centerCrop"

Here is my complete code:

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

    <ImageView
        android:id="@+id/imageBackgroundAboutFragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scaleType="fitXY"
        android:adjustViewBounds="true"
        android:src="@drawable/about_us_background"/>
</RelativeLayout>
2

2 Answers

0
votes

Use android:scaleType="fitXY" with android:adjustViewBounds

UPDATE

I think you should do some trial and errors :

How to scale an Image in ImageView to keep the aspect ratio

Scale Image to fill ImageView width and keep aspect ratio

So many possible fix, but i dont really sure which one will work for you (my answer working for me but not for you - for example).

0
votes

updtae your imageview like this..

remove scaleType and adjustViewBounds.. and make layout_height as match_parent

<ImageView
    android:id="@+id/imageBackgroundAboutFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:src="@drawable/about_us_background"/>