androidxmllayoutscrollviewadjustpan

Blank space when using ScrollView Activity in combination with adjustPan


My Linear Layout was taking too much space. So I decided to put it inside a ScrollView.

The layout has an EditText at the bottom for user input. To make the layout resize itself in AndroidManifest.xml for the Activity I put:

android:windowSoftInputMode="adjustPan"

It was OK for when I just had a Linear Layout, but now in combination with Scroll View I get a blank space, I think Android is trying to make space for the keyboard.

Layout.xml:

<ScrollView android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android">
<androidx.appcompat.widget.LinearLayoutCompat
    android:isScrollContainer="false"
    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"
    android:orientation="vertical"
    tools:context=".MainActivity"
    android:background="@color/colorPrimary">

    ...

</androidx.appcompat.widget.LinearLayoutCompat>
</ScrollView>

Before clicking keyboard

After clicking keyboard


Solution

  • Replace with following code

        <ScrollView android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fillViewport="true" 
            xmlns:android="http://schemas.android.com/apk/res/android">
    
        <androidx.appcompat.widget.LinearLayoutCompat
            android:isScrollContainer="false"
            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"
            android:orientation="vertical"
            tools:context=".MainActivity"
            android:background="@color/colorPrimary">
    
            ...
    
        </androidx.appcompat.widget.LinearLayoutCompat>
        </ScrollView>