1

I have a next problem.

Structure of my layout is:

<RelativeLayout>
   <AppBarLayout>
      <Toolbar></Toolbar>
   </AppBarLayout>
   <FrameLayout> Here I load fragments  </FrameLayout>
   <Footer></Footer>
</RelativeLayout>

I want to use feature:

android:windowSoftInputMode="adjustResize"

in my activity, but the problem is that the footer going up on keyboard open. I don't know how to prevent only footer to be moved but all other views to be. I'm searching for days for the solution but without success.

When I set:

android:windowSoftInputMode="adjustPan"

footer is not moving which is good, but forms with EditText are covered with keyboard which is annoying and bad UI/UX.

My footer has a

android:layout_alignParentBottom="true"

Here is the full XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_logged_in"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.widget.AppBarLayout
    android:id="@+id/main_app_bar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <android.support.v7.widget.Toolbar
        android:id="@+id/main_app_toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light">


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

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


<LinearLayout
    android:id="@+id/bottom_navigation"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentEnd="true"
    android:layout_alignParentStart="true"
    android:orientation="horizontal"
    android:paddingBottom="5dp"
    android:paddingTop="5dp">

    <!-- Footer goes here -->

</LinearLayout>


<FrameLayout
    android:id="@+id/fragment_logged_in_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@id/bottom_navigation"
    android:layout_below="@id/main_app_bar" />

</RelativeLayout>

Thanks in advance

Igor Janković
  • 5,494
  • 6
  • 32
  • 46

2 Answers2

0
<?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"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/main_app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.v7.widget.Toolbar
            android:id="@+id/main_app_toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light">


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

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

    <FrameLayout
        android:id="@+id/fragment_logged_in_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1">

        </FrameLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">


    </LinearLayout>


</LinearLayout>

This worked for me.

Mohit Kacha
  • 484
  • 2
  • 12
0

First of all, use <RelativeLayout> as your layout root.

Now you can stack your content in two ways:

  1. From above
  2. From below

Say you have five pieces of content A - E. You want only E to move up when your app window resizes from the bottom (that is: the keyboard shows from below). So what you want to do is, start stacking A - D from above, and stack E from below.

Here is an example. Unnecessary attributes are left out for sake of brevity.

<RelativeLayout
    android:layout_width="match_parent" 
    android:layout_height="match_parent">

<AnyView
    android:id="@+id/A"
    android:layout_alignParentTop="true"/>

<AnyView
    android:id="@+id/B"
    android:layout_below="@+id/A"/>

<AnyView
    android:id="@+id/C"
    android:layout_below="@+id/B"/>

<AnyView
    android:id="@+id/D"
    android:layout_below="@+id/C"
    android:layout_above="@+id/E"/> <!-- this one will fill any space left out after adding views A, B, C, and E -->

<AnyView
    android:id="@+id/E"
    android:layout_alignParentBottom="true"/>


</Relativelayout>

So basically what happens is that when your keyboard shows, the bottom anchor of the screen moves up. When you say android:layout_alignParentBottom="true", this will keep that view just above this bottom anchor.

But as far as other views (A, B, C, and D) are concerned, they are not directly dependent upon that bottom anchor. So, they will not move or adjust themselves.

Just one thing to keep in mind. When you build your layout like this (a little stacked from the top, and a little from the bottom), there will always be one specific view that will have a variable height, and will adjust to changing screen heights. In the above example, that view is D.

Abdul Wasae
  • 3,614
  • 4
  • 34
  • 56
  • Please check my layout and you will see that you wrote what I actually did and it doesn't work. Sorry in advance if I've missed something different. Or you did not understand my question. I want footer to not be moved from the bottom of the screen. – Igor Janković May 23 '17 at 13:21
  • You have set your @id/navigationBottom anchored to the bottom. You should not do that if you want your footer to not move when keyboard comes up. Align to parent top and then give it some margin or anything. – Abdul Wasae May 23 '17 at 14:03