Rune Borgen
Rune Borgen

Reputation: 369

Overlapping fragments when soft keyboard appears

I've got an activity with several fragments, in particular:

<LinearLayout
    android:orientation="vertical"
    android:layout_width="1056dp"
    android:layout_height="match_parent">
    <fragment
        android:layout_width="1056dp"
        android:layout_height="0dp"
        android:name="FragEntryEdit"
        android:id="@+id/itemEditFragment"
        tools:layout="@layout/fragment_entry_edit"
        android:layout_weight="2"
        />

    <ScrollView
        android:layout_width="1056dp"
        android:layout_height="0dp"
        android:layout_weight="1.5">
        <fragment
            android:layout_width="1056dp"
            android:layout_height="match_parent"
            android:name="FragPhotos"
            android:id="@+id/itemPhoto"
            tools:layout="@layout/fragment_photos"
            />
    </ScrollView>
</LinearLayout>

The first fragment contain a few EditText controls some of which are multi-line.

When creating, I hide the soft keyboard. When an editText control gets focus, the soft keyboard appears.

However the content of the second fragments (which is beneath the first) is pushed up by the keyboard, overlapping the EditText-controls (the first fragment).

I have tried to set set the 'windowSoftInputMode' to 'AdjustPan', but this doesn't appear to work.

Anybody got any suggestions?

Upvotes: 0

Views: 1357

Answers (2)

Rune Borgen
Rune Borgen

Reputation: 369

Figured it out! The problem was not the fragments, but the vertical weighting in the LinearLayouts. I removed the weighting and wrapped a ScrollView around the first fragment, and it works.

Upvotes: 1

mario595
mario595

Reputation: 3761

I would suggest to set a background to the fragments. I had a similar problem with overlapping fragment and I solved it setting a white background to the fragments.

my_fragment.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white"
    android:orientation="vertical" >

    <!-- MORE XML -->

</LinearLayout>

Upvotes: 0

Related Questions