0

I have the following layout

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:animateLayoutChanges="true">

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

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

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

    <ScrollView
        android:id="@+id/scroll_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true">

        <!-- Content -->

    </ScrollView>

    <include layout="@layout/fixed_layout_when_keyboard_not_visible" />

</RelativeLayout>

In AndroidManifest I have the android:windowSoftInputMode set to adjustResize which doesn't 'squeeze' the content when keyboard is visible and keeps the Toolbar fixed at all times, even when I scroll. However, I have another view at the bottom, out of the ScrollView, which I want to be fixed as well but at the same time not block any content when keyboard pops up- right now it moves with the keyboard as of the following property layout_gravity="bottom".

I could just toggle the visibility of that layout when keyboard shows/hides but that doesn't seem the most elegant solution. What would you suggest? Any help very much appreciated :)

zbx
  • 279
  • 1
  • 3
  • 11
  • I believe listening for the soft keyboard and hide/show the view is the best way to achieve what you require. Default behavior of android is ether show or hide whole content. – X3Btel Nov 29 '16 at 20:34

2 Answers2

0

You should solve the issue by telling the ScrollView to not register as a scroll container by adding android:isScrollContainer="false". Your new ScrollViewshould look like this:

<ScrollView
     android:id="@+id/scroll_view"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:fillViewport="true"
     android:isScrollContainer="false">

        <!-- Content -->

</ScrollView>
BradleyIW
  • 1,338
  • 2
  • 20
  • 37
  • Wouldnt that hide content under the keyboard, not only the included view but scrollview items as well – X3Btel Nov 29 '16 at 15:29
  • well you can scroll to the components you want inside the ScrollView, and if the OP is wanting to toggle the visibility of the components below the ScrollView, i can only assume they aren't deemed important enough to get to without having the keyboard displayed. – BradleyIW Nov 29 '16 at 15:38
  • Hm, I tried it and unfortunately it didn't change anything. The layout below the ScrollView still moves w/ the keyboard – zbx Nov 30 '16 at 10:07
0

Try below code

  <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
        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:orientation="vertical"
        android:layout_height="match_parent"
        android:animateLayoutChanges="true">

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

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

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

        <ScrollView
            android:id="@+id/scroll_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fillViewport="true">

            <!-- Content -->

        </ScrollView>


    </RelativeLayout>
Surya Prakash Kushawah
  • 3,185
  • 1
  • 22
  • 42
  • Changing RelativeLayout to LinearLayout didn't do the job unfortunately, thanks for the advice though :) – zbx Nov 30 '16 at 10:05