1

In one Android-Activity, I have some Input-fields with some Buttons below that. Because I don't the Softkeyboard to push everything up and want to give the user the ability to navigate to a different Input-field quite easy, i put the Input-fields and the buttons into a ScrollView.

Now I want the Buttons to be at the bottom of the screen, when the softkeyboard is closed
and just below the Input-fields in the ScrollView, when keyboard is opened.
If I add

android:layout_below="@id/input_fields"

the buttons are always below the input-fields, but not at the bottom of the screen.

android:layout_alignParentBottom="true"

aligns them to bottom, but when keyboard is open, they are in front of the last input-fields.

Does anybody know what to do?

A example of my layout-file:

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >


        <RelativeLayout
            android:id="@+id/input_fields"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" 
            android:layout_alignParentTop="true" >

                   <!-- some input-fields -->

        </RelativeLayout>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"

            android:layout_alignParentBottom="true"
            android:layout_below="@id/input_fields"

            android:padding="5dp">

            <!-- 2 buttons -->

        </LinearLayout>
</RelativeLayout>

If you need more information: just ask!
Thanks for any help in advance!

EDIT: some further information:

With "in front of" I mean, that the Buttons were "hiding" the input-fields, because they weren't aligned to the input-fields-layout, but to the end of the parent layout (which was a RelativeLayout inside a ScrollView). This is gone, when I use your suggestion, but then the buttons are always visible right above the keyboard (I did it that way before, but I would like to do it a little bit different, to save some space). I would like to have the buttons in that ScrollView right after the input-fields when the Keyboard is opened. So that you can just see the ScrollView and if you scroll to the end of it, at the bottom (after the input-fields) you should see the buttons. That wont be a problem, but I want the buttons to stay at the bottom of the screen when keyboard is closed regardless of whether the ScrollView fills all the space. Would be nice if you have some ideas!

Klumbe
  • 370
  • 2
  • 12

1 Answers1

-1

Add your fields in ScrollView and place your buttons outside ScrollView like this:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="1" >

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

        <!-- some input-fields -->

        <EditText
            android:id="@+id/editText1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:ems="10" >

            <requestFocus />
        </EditText>

        <EditText
            android:id="@+id/editText2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:ems="10" />
    </LinearLayout>
</ScrollView>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:padding="5dp" >

    <!-- 2 buttons -->

    <Button
        android:id="@+id/button1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Button" />

    <Button
        android:id="@+id/button2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Button" />
</LinearLayout>

</LinearLayout>

Also use

<activity android:windowSoftInputMode="adjustResize" . . . >

in your activity tag. Please check this http://developer.android.com/guide/topics/manifest/activity-element.html#wsoft

M-Wajeeh
  • 17,204
  • 10
  • 66
  • 103
  • Thanks for your help, but i tried something like this before. Now the buttons aren't in front of the input-fields, but they are always vibible. I want them to be at the end of the ScrollView! Any ideas? – Klumbe Jan 31 '13 at 20:22
  • What do you mean "in front of" or "at the end" ? Draw a sketch to explain or use the words that have precise meanings. – M-Wajeeh Feb 01 '13 at 08:53
  • If i would only be able to upload pictures, I would have done screenshots, but i will try to explain it a litte bit more (see Edit of my Question --> at the end) Thanks again for your help! – Klumbe Feb 01 '13 at 17:00