-1

I am attempting to stretch a 300x300 image to fill the parent as a background for a sample layout. However, it seems that at most it can reach it's max dimensions as a perfect square. Here is my code.

<ImageView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:src="@drawable/app_background"
        android:scaleType="fitCenter"
        android:adjustViewBounds="true"/>

There is still white space at both the top and bottom of the app and I want to eliminate that. Any and all solutions to this dilemma would be greatly appreciated.enter image description here

Tim Slim
  • 29
  • 1
  • 3
  • 1
    why not setting parent's `android:background` to `@drawable/app_background`? **EDIT**: as @Chisko suggested you can also use `android:scaleType="fitXY"` in your `ImageView` – Stefan Golubović Mar 19 '18 at 21:56
  • 1
    play around with `android:scaleType`, the `fitCenter` current option is the responsible of the "perfect sqaure" thing – Chisko Mar 19 '18 at 21:59
  • OMG thank you Stefan Golubovic! I would have never known about this Without your help. – Tim Slim Mar 19 '18 at 22:05

4 Answers4

0

Use match_parent

<ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:src="@drawable/app_background"
    android:scaleType="fitCenter"
    android:adjustViewBounds="true"/>
Pedro Massango
  • 4,114
  • 2
  • 28
  • 48
0

Worked for me:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  tools:context="org.jtb.stretchtest.MainActivity">

  <ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scaleType="fitCenter"
    android:src="@drawable/test"/>
</RelativeLayout>

enter image description here

Jeffrey Blattman
  • 22,176
  • 9
  • 79
  • 134
0

Check if the parent element has paddings.

Set Android padding of the parent widget to 0dp Eg: android:padding = "0dp"

0

This works for me:

<ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="fitXY"
        android:src="@drawable/app_background"/>
ruben
  • 1,745
  • 5
  • 25
  • 47