0

I searched the NET but did not find a solution to my problem. I have a form with few textViews and EditTexts. At the bottom of the screen I positioned 3 buttons. In order to fix them at the bottom of the screen I had to have them outside the scrollView as explained in How to make a static button under a ScrollView?.

However, when the soft keyboard opens as I enter text in one of the edittext, the buttons moves up to be just above the soft keyboard, covering some of edittext elements.

I want the buttons to stay at the bottom of the screen such that the softkeyboard covers them. In order to do it I have to include them in the scrollView, but then I can not position them at the bottom of the screen when the softkeyboard is closed.

Here is my XML

<?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"
android:background="@color/bgcolor"
android:orientation="vertical"
android:paddingTop="5dp">

<LinearLayout
    android:id="@+id/linearLayout2"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:visibility="visible">

    <TextView
        android:id="@+id/list_title2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:text="@string/xml_text_text"
        android:textColor="@color/textColor"
        android:visibility="gone" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="5dp"
        android:gravity="center"
        android:padding="10dp"
        android:text="@string/category_adding"
        android:textColor="@color/myColor"
        android:textSize="18sp"
        android:textStyle="bold" />

    <ScrollView
        android:id="@+id/scrollView2"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:isScrollContainer="true"
        android:orientation="vertical"
        android:visibility="visible">

        <RelativeLayout
            android:id="@+id/categoryLayout2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginEnd="10dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginStart="10dp"
            android:orientation="vertical"
            android:visibility="visible">

            <TextView
                android:id="@+id/categoryQuestionNumber"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/category_add_question_number"
                android:textColor="@color/myColor"
                android:textSize="18sp" />

            <talkie.feedback.NumberPickerHorizontal
                android:id="@+id/horizontal_number_picker"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_alignParentRight="true" />

            <android.support.design.widget.TextInputLayout
                android:id="@+id/questionPromptWrapper"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/categoryQuestionNumber"
                android:layout_marginTop="2dp"
                android:hint="@string/category_add_question">

                <android.support.design.widget.TextInputEditText
                    android:id="@+id/questionPrompt"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:drawableLeft="@drawable/user"
                    android:drawableStart="@drawable/user"
                    android:ems="45"
                    android:imeOptions="actionNext"
                    android:singleLine="true"
                    android:textColor="@color/myColor"
                    android:textSize="18sp" />
            </android.support.design.widget.TextInputLayout>

            <android.support.design.widget.TextInputLayout
                android:id="@+id/questionExplanationWrapper"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/questionPromptWrapper"
                android:layout_marginTop="2dp"
                android:hint="@string/category_add_explanation">

                <android.support.design.widget.TextInputEditText
                    android:id="@+id/questionExplanation"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:drawableLeft="@drawable/user"
                    android:drawableStart="@drawable/user"
                    android:ems="45"
                    android:imeOptions="actionDone"
                    android:singleLine="true"
                    android:textColor="@color/myColor"
                    android:textSize="18sp" />
            </android.support.design.widget.TextInputLayout>

            <Button
                android:id="@+id/add"
                android:layout_width="130dp"
                android:layout_height="30dp"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_below="@+id/questionExplanationWrapper"
                android:layout_marginLeft="20dp"
                android:layout_marginStart="20dp"
                android:background="@drawable/border_round_corners_thin_mycolor_bkg"
                android:text="@string/category_add_add_question"
                android:textColor="@color/simple_white"
                android:textSize="13sp"
                android:textStyle="bold" />

            <Button
                android:id="@+id/delete"
                android:layout_width="130dp"
                android:layout_height="30dp"
                android:layout_alignParentEnd="true"
                android:layout_alignParentRight="true"
                android:layout_below="@+id/questionExplanationWrapper"
                android:layout_marginEnd="20dp"
                android:layout_marginRight="20dp"
                android:background="@drawable/border_round_corners_thin_mycolor_bkg"
                android:text="@string/category_add_delete_question"
                android:textColor="@color/simple_white"
                android:textSize="13sp"
                android:textStyle="bold" />

            <RelativeLayout
                android:id="@+id/categoryLayout3"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/delete"
                android:layout_marginTop="2dp"
                android:background="@drawable/border_round_corners_thin_blue"
                android:padding="10dp"
                android:visibility="visible">

                <android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
                    android:id="@+id/recyclerview2"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center" />
            </RelativeLayout>
        </RelativeLayout>
    </ScrollView>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_below="@+id/categoryLayout2"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="10dp"
        android:orientation="horizontal"
        android:visibility="visible"
        android:weightSum="3">

        <Button
            android:id="@+id/save2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_weight="1"
            android:background="@drawable/btn_background"
            android:text="@string/save_action"
            android:textAllCaps="false"
            android:textColor="@color/simple_white" />

        <Button
            android:id="@+id/return2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_marginLeft="5dp"
            android:layout_marginStart="5dp"
            android:layout_weight="1"
            android:background="@drawable/btn_background_blue"
            android:text="@string/category_add_category"
            android:textColor="@color/simple_white"
            android:textStyle="bold" />

        <Button
            android:id="@+id/exit2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_marginLeft="5dp"
            android:layout_marginStart="5dp"
            android:layout_weight="1"
            android:background="@drawable/btn_background_exit"
            android:text="@string/register_return"
            android:textAllCaps="false"
            android:textColor="@color/simple_white" />

    </LinearLayout>


</LinearLayout>

Community
  • 1
  • 1
Zvi
  • 2,354
  • 2
  • 26
  • 37
  • 1
    In your manifest, for the activity in question, use `android:windowSoftInputMode="adjustPan"` – Aleks G May 19 '16 at 16:05
  • Yes that did it. But I read somewhere that adjustPan can cause a problem compared to adjustResize. Can you elaborate about it? – Zvi May 19 '16 at 16:09
  • I use adjustPan in my app for exactly the same reason as you described and have no problem. Can you elaborate on _"I read somewhere that adjustPan can cause a problem"_? Where did you read this? And what king of problem? – Aleks G May 19 '16 at 16:11
  • see http://stackoverflow.com/questions/17410499/difference-between-adjustresize-and-adjustpan-in-android – Zvi May 19 '16 at 19:04

2 Answers2

1

[Posting an answer from my own comment.]

In your manifest, for the activity in question, use

android:windowSoftInputMode="adjustPan"

I use this in my own app for exactly the same reason (i.e. buttons at the bottom cover the text being typed in) - and it works exactly the way I need.

Aleks G
  • 56,435
  • 29
  • 168
  • 265
0

in your manifest file if you have put "android:windowsSoftInputMode="adjustPan| adjustResize" then remove it.

In second step after removing what I have said in first line, try to run app without "android:windowsSoftInputMode", because for me it gave me the same solution that you are looking for.

but if doesn't work after removing "windowsSoftInputMode" , then provide "android:windowSoftInputMode="adjustPan" and run the app

Mrugesh
  • 4,381
  • 8
  • 42
  • 84