Tomer
Tomer

Reputation: 17930

Android: How do I configure RelativeLayout to fill the entire height

I have a scroll view that contains a relative layout. The scroll view has a gradient background and is set to fill parent. The relative layout also have a BG and i'd like it to fill the screen as well but android:layout_height="fill_parent" is not applicable for relative layout.

How can I configure the RelativeLayout to span the entire screen height on any screen resolution?

Here is my code:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/parentLayout"
    style="@style/mainLayoutStyle"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <RelativeLayout
        android:id="@+id/RelativeLayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/home_activity_bg"
        android:paddingBottom="10dp" >


    </RelativeLayout>

</ScrollView>

UPDATE:

I removed everything and left the just the ScrollView and the RelativeLayout, for some reason, on Galaxy S4 the image is cut before the end (you can see according to the blue lines that the Layout itself ends just before the end):

enter image description here

Upvotes: 1

Views: 678

Answers (3)

Tomer
Tomer

Reputation: 17930

Ended up using the following code:

private void setHeightToFullScreen() {
        Display display = getWindowManager().getDefaultDisplay();
        int height = display.getHeight();
        RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.myRelativeLayout);
        LayoutParams layoutParams = relativeLayout.getLayoutParams();
        layoutParams.height = height;
    }

please note that getHeight is deprecated and you should use getSize, but that is only supported in API level 13.

Upvotes: 0

Rotary Heart
Rotary Heart

Reputation: 1969

You have that cut because of this "android:paddingBottom="10dp" remove that line from your RelativeLayout and it will fill the screen.

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/parentLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ffff00" >

    <RelativeLayout
        android:id="@+id/RelativeLayout1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#ff0000" >


    </RelativeLayout>

</ScrollView>

This is my code and this is my display:

enter image description here

Upvotes: 1

Terry
Terry

Reputation: 14867

At the RelativeLayout, remove the android:paddingBottom="10dp" and make it android:layout_height="fill_parent".

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/parentLayout"
    style="@style/mainLayoutStyle"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <RelativeLayout
        android:id="@+id/RelativeLayout1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/home_activity_bg" >

    </RelativeLayout>

</ScrollView>

Upvotes: 0

Related Questions