0
  1. Image with size (width: 1080px height: 1920px)
  2. Phone is xxhdpi which has a resolution of (width: 1080px height: 1920px)

In output you can see there is a white gap in start and end of the imageView.

I don't want to use android:scaleType="fitXY" because it stretches the image. I know the gaps is because of the status bar and navigation bar the imageview tries to maintain its ratio.

Is it possible to fill the imageview without doing anything to the image source.Thanks in advance.

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

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

Output: sample output

Sai
  • 15,188
  • 20
  • 81
  • 121
  • 2
    Your screen is same size with picture but it have to show status bar and virtual navigation. – Harry T. Jan 17 '17 at 07:34
  • `scaleType="fitXY"` – D.J Jan 17 '17 at 07:35
  • add `scaleType="fitXY"` to your imageview in xml – Vivek Mishra Jan 17 '17 at 07:35
  • @TruongHieu I know. but is there any work around. How can i make it constant in all the phone with virtual navigation and without virtual navigation bar? – Sai Jan 17 '17 at 07:36
  • Make it becomes fullscreen activity – Harry T. Jan 17 '17 at 07:37
  • I can't do that. But i can resize the image can u tell me what image size can i use so that it will fit properly. – Sai Jan 17 '17 at 07:38
  • 1
    You can't do what you seem to want. You have an image that's NxM. You have a phone screen that's Nx(M-H). That means when you display it, you either have to stretch it to fit, or you have bands on the sides. You can change the color of those bands, but that's about all. Its a simple matter of math. For something this small of a difference I'd stretch to fit, the artificating should be minimal – Gabe Sechan Jan 17 '17 at 07:38
  • Use android:scaleType="centerCrop" in your imageView – Siraj Sumra Jan 17 '17 at 07:38
  • try this, http://stackoverflow.com/questions/41611512/how-to-fit-url-image-into-the-screen-on-android/41611852#41611852 – Meena Dev Jan 17 '17 at 07:39
  • `android:adjustViewBounds="true"` – IntelliJ Amiya Jan 17 '17 at 07:39
  • You can simply use "cropXYZ" instead of "XYZ" for your scaleType. This will cause that the image is adapted to the available space without loosing the image aspect ratio – Robin Vinzenz Jan 17 '17 at 07:39
  • Is putting activity in fullscreen mode acceptable solution? – Aleksandar G Jan 17 '17 at 07:41
  • @RobinVinzenz Can u explain bit more. there is nothing called cropXYZ in scaleType – Sai Jan 17 '17 at 07:42
  • @AlexandarG No, that is not my requirement. – Sai Jan 17 '17 at 07:42
  • There is no built-in scale type that allows the ImageView to automatically upscale the image and keep its aspect ratio intact i guess,you need a work around.. http://stackoverflow.com/questions/8232608/fit-image-into-imageview-keep-aspect-ratio-and-then-resize-imageview-to-image-d and http://stackoverflow.com/questions/6202000/imageview-one-dimension-to-fit-free-space-and-second-evaluate-to-keep-aspect-rat – Charuක Jan 17 '17 at 07:48

1 Answers1

1

Since you don't want to use fitXY,or modify the img,maybe you can use android:background="@drawable/img" replace android:src=@drawable/img,Did you like this?

志威梦
  • 136
  • 3