Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ScrollView white space at bottom

I'm having an issue with ScrollView which leaves a blank space at the bottom. It is filled with few TextViews and GridViews and should fill the whole RelativeLayout parent.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    tools:context=".showPictures">
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
            <TextView.../>
            <GridView.../>
        ...
        </LinearLayout>
    </ScrollView>
</RelativeLayout>

Does anybody have an idea what's wrong?

like image 685
user3127162 Avatar asked Mar 07 '15 17:03

user3127162


3 Answers

Make your relative layout height match parent, also use android:fillViewPort = "true" in your scroll view

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".showPictures">
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true">

//...
like image 88
Sushant Avatar answered Sep 28 '22 17:09

Sushant


you can use this code to avoid extra padding on bottom of scroll view:

android:overScrollMode="never"
like image 45
nariman amani Avatar answered Sep 28 '22 17:09

nariman amani


In my case I had a GridView inside a ScrollView that was causing this issue. It turns out the the layout_gravity in the GridLayout as 'center' was causing this issue.

'center_horizontal' makes more sense for a ScrollView anyway, but I added the ScrollView after the original layout was done (using 'center'), when I saw that the elements were going off-screen on some devices, hence the issue.

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <GridLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"  // having this as android:layout_gravity="center" causes extra space at bottom!
        android:columnCount="2">

        ....
like image 26
aaronvargas Avatar answered Sep 28 '22 17:09

aaronvargas