5

I need a fragment with a header and a footer. The content which is in between (of course) needs to be scrollable. Up to there everything is going just fine. But inside of the scrollview needs to be an edittext, so at a certain moment the keyboard will come up. Unfortunately enough the keyboard also brings up the footer OR when I change the windowSoftInputMode to adjustPan it hides the header.

In short what I want to achieve is that the footer stays at the bottom, but the content of the scrollview scrolls up (when the keyboard gets the focus on the edittext). Also the header needs to be visible all the time.

Any suggestions on how to accomplish this behavior?

vanleeuwenbram
  • 1,289
  • 11
  • 19
  • I have the same problem... adjustPan doesnt really do it, as the scrolling doesnt work (my content is inside a ScrollView) – Ted Jan 13 '13 at 13:43
  • I worked with something similar problem in the following link. My Activity had top toolbar as a header and a view hierarchy with contained footer button. http://stackoverflow.com/questions/10599451/how-to-make-an-android-view-scrollable-when-the-keyboard-appears/38210659#38210659 – Sandeep Sharma Jul 05 '16 at 19:13

2 Answers2

0

Android Header footer and scrollable content(Body)

You can try the following:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout
        android:id="@+id/header"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:padding="10dp" >

        <TextView
            android:id="@+id/TextView01"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="header"
            android:textSize="40sp" >
        </TextView>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/footer"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:padding="10dp" >

        <TextView
            android:id="@+id/TextView02"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="footer"
            android:textSize="40sp" >
        </TextView>
    </LinearLayout>

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@id/footer"
        android:layout_below="@id/header" >

        <LinearLayout
            android:id="@+id/body"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <EditText
                android:id="@+id/edit1"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:padding="10dp" />

            <EditText
                android:id="@+id/edit2"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:padding="10dp" />

            <EditText
                android:id="@+id/edit3"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:padding="10dp" />

            <EditText
                android:id="@+id/edit4"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:padding="10dp" />

            <EditText
                android:id="@+id/edit5"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:padding="10dp" />

            <EditText
                android:id="@+id/edit6"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:padding="10dp" />

            <EditText
                android:id="@+id/edit7"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:padding="10dp" />

            <EditText
                android:id="@+id/edit8"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:padding="10dp" />

            <Button
                android:id="@+id/btn"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Submit" />
        </LinearLayout>
    </ScrollView>

</RelativeLayout>

Add android:windowSoftInputMode="adjustPan" to your activity in Android manifest.

Ral Zarek
  • 1,058
  • 4
  • 18
  • 25
SonuAsher
  • 9
  • 1
0

did u try android:isScrollContainer="false" ?

Aditya
  • 389
  • 2
  • 4
  • on the scrollview? or footer? or...? – vanleeuwenbram Mar 20 '12 at 10:55
  • on the scrollview? or footer? or...? EDIT: when i put isScrollContainer on the scrollview it behaves the same as when I use AdjustPan, so not really what i want – vanleeuwenbram Mar 20 '12 at 11:20
  • Nope...managed to work around it a little bit... I think there might be something you can do at a higher level if you try to draw in the TOP container (the one that contains the actionbar)...but haven't tried yet – vanleeuwenbram Jan 14 '13 at 09:10