Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Footer goes up when the keyboard is displayed

I've been searching for the solution for this problem but I didn't find any that could solve my problem.

I'm using RelativeLayout as my main layout and my footer is RelativeLayout too, I found in the internet these configurations:

android:windowSoftInputMode="adjustPan|adjustResize"

It works for the footer stays fixed but my scroll does not work, that's my main problem, what can I do for solving it?

My layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/background"
    android:focusable="true"
    android:fitsSystemWindows="true"
    android:orientation="vertical" >

    <ScrollView
        android:id="@+id/scrollView1"
        android:fillViewport="true"
        android:isScrollContainer="true"
        android:fitsSystemWindows="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <LinearLayout 
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

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

                <TextView
                    android:id="@+id/ttvp1"
                    style="@style/ttvPersonalizado"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/p1" />

                <TextView
                    android:id="@+id/ttvp2"
                    style="@style/ttvPersonalizadoDireito"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/p2" />
            </LinearLayout>

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


                <EditText
                    android:id="@+id/edtP1"
                    style="@style/edtPersonalizado"
                    android:maxLength="5"
                    android:layout_height="wrap_content"
                    android:background="@drawable/edit_text_design"
                    android:ems="10"
                    android:inputType="numberDecimal" >
                </EditText>

                 <EditText
                    android:id="@+id/edtP2"
                    style="@style/edtPersonalizado"
                    android:maxLength="5"
                    android:layout_height="wrap_content"
                    android:background="@drawable/edit_text_design"
                    android:ems="10"
                    android:inputType="numberDecimal" />

            </LinearLayout>

            <TextView
                android:id="@+id/ttvpim"
                style="@style/ttvPersonalizado"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="@string/pip3" />

            <EditText
                android:id="@+id/edtPiP3"
                style="@style/edtPersonalizado"
                android:maxLength="5"
                android:layout_height="wrap_content"
                android:background="@drawable/edit_text_design"
                android:inputType="numberDecimal" />

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

                <TextView
                    android:id="@+id/ttvExame"
                    style="@style/ttvPersonalizado"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:paddingRight="18dp"
                    android:text="@string/notaExame" />

                <CheckBox
                    android:id="@+id/chkExame"
                    style="@style/chkPersonalizado"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="40dp"
                    android:text="@string/exame" />
            </LinearLayout>

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

                <EditText
                    android:id="@+id/edtExame"
                    style="@style/edtPersonalizado"
                    android:maxLength="5"
                    android:layout_height="wrap_content"
                    android:background="@drawable/edit_text_design"
                    android:ems="10"
                    android:enabled="false"
                    android:inputType="numberDecimal"
                    android:width="125dp" />

                <CheckBox
                    android:id="@+id/chkPersonalizado"
                    style="@style/chkPersonalizado"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/tecnologo" />
            </LinearLayout>

            <TextView
                style="@style/ttvPersonalizado"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="@string/mediaFinal" />

            <EditText
                android:id="@+id/edtMedia"
                style="@style/edtPersonalizado"
                android:maxLength="5"
                android:layout_height="wrap_content"
                android:background="@drawable/edit_text_design"
                android:enabled="false"
                android:inputType="numberDecimal" />

            <TextView
                android:id="@+id/ttvStatus"
                style="@style/ttvPersonalizado"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="" />

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

                <ImageButton
                    android:id="@+id/btnGerarMedia"
                    style="@style/btnMedio"
                    android:background="@drawable/shapebutton"
                    android:contentDescription="@string/gerarMedia"
                    android:src="@drawable/icone_calculadora"
                    android:text="@string/gerarMedia" />
            </LinearLayout>
        </LinearLayout>
    </ScrollView>

    <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="50dip"
    android:layout_alignParentBottom="true"
    android:background="@drawable/background_footer"
    android:orientation="vertical" >

    <com.google.ads.AdView
        android:id="@+id/adView"
        android:layout_width="fill_parent" />


</RelativeLayout>

</RelativeLayout>

My activity configuration in AndroidManifest:

<activity
            android:name="br.com.media_universidades.visao.MediaCalculoActivity"
            android:icon="@drawable/ic_launcher"
            android:label="@string/umc" android:windowSoftInputMode="adjustPan|adjustResize"/>

Thank you in advance.

like image 576
Rafael Chinelato Del Nero Avatar asked Jan 08 '16 23:01

Rafael Chinelato Del Nero


People also ask

How do I stop my footer from moving?

If you want to keep the footer at the bottom of the text (sticky footer), but keep it from always staying at the bottom of the screen, you can use: position: relative; (keeps the footer in relation to the content of the page, not the view port) and clear: both; (will keep the footer from riding up on other content).

How do I keep the footer fixed to the bottom?

Keep the footer at the bottom by using Flexbox Make sure that you are wrapping everything in a <div> or any other block-level element with the following CSS styles: min-height:100vh; display:flex; flex-direction:column; justify-content:space-between; .

How do I fix a header and footer?

You can easily create sticky or fixed header and footer using the CSS fixed positioning. Simply apply the CSS position property with the value fixed in combination with the top and bottom property to place the element on the top or bottom of the viewport accordingly.

How do I keep my mobile keyboard from covering HTML input?

Adding a padding to the bottom of the page that is large enough for the keyboard enables content to be displayed as desired when the keyboard is visible.


1 Answers

Depending on which version on android you are using and how your layout is will have a different solution:

<activity
    android:name="br.com.media_universidades.visao.MediaCalculoActivity"
                android:icon="@drawable/ic_launcher"
                android:label="@string/umc" 
    android:windowSoftInputMode="adjustResize"> 

Edit: fixed the above code as the pervious answer I wrote was using this

android:windowSoftInputMode="stateVisible|adjustResize"/>

But sometime you have to force it by using the code in onCreate() method:

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

Here is a fix and here is the doc on this.

The setting must be one of the values listed in the following table, or a combination of one "state..." value plus one "adjust..." value. Setting multiple values in either group — multiple "state..." values, for example — has undefined results. Individual values are separated by a vertical bar (|). For example:

But I didnt read OP question correctly and hes scrollview isn't moving. This requires a OnGlobalLayoutListener()which is added to the scroll view.

final View activityRootView = findViewById(R.id.activityRoot);
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
    Rect r = new Rect();
    //r will be populated with the coordinates of your view that area still visible.
    activityRootView.getWindowVisibleDisplayFrame(r);

    int heightDiff = activityRootView.getRootView().getHeight() - (r.bottom - r.top);
    if (heightDiff > 100) { // if more than 100 pixels, its probably a keyboard...
        ... do something here
    }
 }
}); 

Here are some awesome way to do it. The code above is from @Kachi.

like image 118
S A Avatar answered Oct 13 '22 20:10

S A