Coordinatorlayout adjustresize not working

hexhog picture hexhog · Sep 21, 2015 · Viewed 10.7k times · Source

MY CODE (and more): I have a Coordinator Layout as follows

<android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapse_toolbar"
            android:layout_width="match_parent"
            android:layout_height="280dp"
            android:fitsSystemWindows="true"
            app:contentScrim="@color/transparent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <include layout="@layout/top" /> <!-- A RelativeLayout -->

            <android.support.v7.widget.Toolbar
                android:id="@+id/MyToolbar"
                android:layout_width="match_parent"
                android:layout_height="64dp"
                app:layout_collapseMode="parallax">

            </android.support.v7.widget.Toolbar>

        </android.support.design.widget.CollapsingToolbarLayout>

    </android.support.design.widget.AppBarLayout>

    <FrameLayout
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <!-- Main content here -->

    </FrameLayout>

</android.support.design.widget.CoordinatorLayout>

Inside the frame layout I am inflating a custom view with an edit text which is placed at the bottom. The edit text and custom view show up fine.

I have defined android:windowSoftInputMode="adjustResize|stateHidden" in the manifest.

MY PROBLEM: While tapping on the edit text to bring up the softkeyboard, it overlaps the content beneath instead of resizing the FrameLayout. I just could not get the FrameLayout to resize when the soft keyboard comes up. Any help will be appreciated

THINGS I TRIED:

  1. Updated design support library to 22.2.1
  2. Added android:layout_gravity="fill_vertical" as an attribute in FrameLayout.

Answer

Michael picture Michael · Mar 31, 2016

Try this


your_layout.xml

<RelativeLayout
    android:fitsSystemWindows="true" > <!-- Crucial! -->

    <android.support.design.widget.CoordinatorLayout>
        ...
        <android.support.v7.widget.RecyclerView />
        ...
    </android.support.design.widget.CoordinatorLayout>

</RelativeLayout>

AndroidManifest.xml

<activity
    android:name=".YourActivity"
    android:windowSoftInputMode="adjustResize"> <!-- Crucial! -->
</activity>