The footer rises when the keyboard is displayed

I was looking for a solution to this problem, but did not find anything that could solve my problem.

I use RelativeLayout as the main layout, and my footer is RelativeLayout, I found the following configurations on the Internet:

Android: windowSoftInputMode = "adjustPan | adjustResize"

It works for the footer, but my scroll does not work, what is my main problem, what can I do to solve 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>

Configuration of my activity in AndroidManifest:

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

Thanks in advance.

+4
source share
1 answer

, :

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

: , , ,

android:windowSoftInputMode="stateVisible|adjustResize"/>

- onCreate():

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

, doc.

, , "..." "...". - "...", , undefined . (|). :

OP- , hes scrollview . OnGlobalLayoutListener(), .

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
    }
 }
}); 

. - @Kachi.

+1

Source: https://habr.com/ru/post/1623491/


All Articles