How to adjust image in android screen under status bar and navigation in android?

Viewed 11

I am using an Imageview to show an image. If I set the image in background then its taking full widths and height under status bar and navigation bar. like as in below screen. And the image is streching.

          <ImageView
                android:id="@+id/imgLoginImageSlider"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/slider2" />

enter image description here

In the second case if I set image using Glide then this same image not taking full widths and height. There is some space in top and bottom of the image. Like in below image.

Glide.with(context).load(model.getDrawable_img()).into(holder.binding.imgLoginImageSlider);

But I want to set the image using programmatically, How to do then. Any help? Thanks in advance. Image should not be streach.

enter image description here

1 Answers

Adding this property to the ImageView will fix your issue

android:scaleType="centerCrop"

Learn more about this here

Related