Search code examples
androidxmlbackgroundfullscreen

Background not filling entire screen in scrollview android


I'm developing an app and I need to fill the entire screen with a background, this view contains a scrollview. The problem is that the background is not covering the entire screen, it has a white stripe at the bottom, like the image below.

I have already tried many options of scaleType, like fitXY, centerInside, etc. none of them worked out. My XML is below.

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:adjustViewBounds="true"
            android:scaleType="centerCrop"
            android:src="@drawable/signup_background" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:padding="40dp">

            <de.hdodenhof.circleimageview.CircleImageView
                android:id="@+id/image_view_photo"
                android:layout_width="130dp"
                android:layout_height="130dp"
                android:layout_gravity="center"
                android:layout_marginBottom="25dp"
                android:src="@drawable/camera_icon" />

            <android.support.v7.widget.AppCompatEditText
                android:id="@+id/edit_text_name"
                style="@style/BaseEditText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:drawableLeft="@drawable/name_icon"
                android:hint="@string/field_name"
                android:inputType="textCapWords" />

            <android.support.v7.widget.AppCompatEditText
                android:id="@+id/edit_text_email"
                style="@style/BaseEditText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:drawableLeft="@drawable/email_icon"
                android:hint="@string/field_email"
                android:inputType="textEmailAddress" />

            <android.support.v7.widget.AppCompatEditText
                android:id="@+id/edit_text_password"
                style="@style/BaseEditText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:drawableLeft="@drawable/password_icon"
                android:hint="@string/field_password"
                android:inputType="textPassword" />

            <android.support.v7.widget.AppCompatEditText
                android:id="@+id/edit_text_confirm_password"
                style="@style/BaseEditText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="35dp"
                android:drawableLeft="@drawable/password_icon"
                android:hint="@string/field_confirm_password"
                android:inputType="textPassword" />

            <com.jacksonueda.reachalert.Utils.LoadingButton
                android:id="@+id/btn_signup"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="10dp"
                android:text="@string/action_sign_up" />
        </LinearLayout>
    </android.support.constraint.ConstraintLayout>
</ScrollView>

Can anyone help me? Thanks.


Solution

  • I got the answer, what I needed to do was to put a RelativeLayout as parent of the ScrollView, like below.

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fillViewport="true">
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/signup_background"
                android:orientation="vertical"
                android:padding="40dp">
    
                ...
    
            </LinearLayout>
        </ScrollView>
    </RelativeLayout>