In AndroidStudio, how do i make the image view adjust its size according to the size of the screen?

31 Views Asked by At

I want the image to shrink or increase in size as i change the screen resolution. Please help!

When i changed the screen size the image became either too small or too big for some screen.

Just using some xml tags is it possible to achieve this. PS:NOOB ME

1

There are 1 best solutions below

0
IamAyanMishra On

You can do this:-

<ImageView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:src="@drawable/your_image"
    android:adjustViewBounds="true"
    android:scaleType="fitCenter" />

Make sure :-

android:layout_width="match_parent" ensures the image width matches the container. android:layout_height="wrap_content" lets the image adjust its height based on its aspect ratio. android:adjustViewBounds="true" and android:scaleType="fitCenter" further fine-tune scaling while maintaining aspect ratio.