Android - Align Layout above the keyboard

Asked

Viewed 1,105 times

2

I have the following layout:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/view_login"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background"
    tools:context=".LoginActivity">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:paddingBottom="50dp"
            android:paddingTop="50dp">

            <ImageView
                android:id="@+id/marca"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_centerHorizontal="true"
                android:layout_marginBottom="50dp"
                android:background="@drawable/marca" />

            <LinearLayout
                android:layout_below="@+id/marca"
                android:id="@+id/form_login"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_marginBottom="50dp"
                android:layout_marginLeft="20dp"
                android:layout_marginRight="20dp"
                android:orientation="vertical">

                <ImageView style="@style/separador" />

                <LinearLayout style="@style/box_field">

                    <ImageView
                        style="@style/icon_field"
                        android:background="@drawable/icon_usuario" />

                    <EditText
                        android:id="@+id/usuario"
                        style="@style/edit_field"
                        android:hint="@string/hint_usuario"
                        android:inputType="textNoSuggestions"/>
                </LinearLayout>

                <ImageView style="@style/separador" />

                <LinearLayout style="@style/box_field">

                    <ImageView
                        style="@style/icon_field"
                        android:background="@drawable/icon_senha" />

                    <EditText
                        android:id="@+id/senha"
                        style="@style/edit_field"
                        android:hint="@string/hint_senha"
                        android:inputType="textPassword"
                        android:imeOptions="actionSend"/>
                </LinearLayout>

                <ImageView style="@style/separador" />

                <RelativeLayout
                    android:id="@+id/botao_entrar"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="40dp"
                    android:background="#009999">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerInParent="true"
                        android:paddingBottom="20dp"
                        android:paddingTop="20dp"
                        android:text="@string/Entrar"
                        android:textColor="#cccccc"
                        android:textSize="16sp" />

                </RelativeLayout>

            </LinearLayout>

        </RelativeLayout>
    </ScrollView>

    <RelativeLayout
        android:id="@+id/msg_login"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_alignParentBottom="true"
        android:gravity="bottom"
        android:visibility="invisible">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:background="#FFFFFF"
            android:paddingBottom="5dp"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:paddingTop="5dp">

            <TextView
                android:id="@+id/txt_msg_login"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:textColor="#233246" />
        </RelativeLayout>
    </RelativeLayout>
</RelativeLayout>

My manifest is like this:

    <activity
        android:name=".LoginActivity"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="adjustResize">
    </activity>

What I need is the following that when opening the keyboard, my screen resize, that is, this entire layout is above the keyboard. Does anyone know any way to do that?

1 answer

1

try to put this

<activity
        android:name=".activities.MainActivity"
        android:windowSoftInputMode="adjustResize|adjustPan">
<activity/>
  • This does not work, it continues in the same way, the keyboard on my layout, as an overlay

  • just let the adjustPan and tell me if it worked

  • also did not give, always continues the keyboard as overlay

  • take off your Scrollview just for testing... and dps change your Relativelayout for Linearlayout... and talk behavior

  • Went on the same way, buddy.

  • Putz... Jah had this problem more just in a dialog... in Activity this code solved... I’ll see another way

  • 'Activity.getWindow(). setSoftInputMode(Windowmanager.LayoutParams.SOFT_INPUT_ADJUST_PAN);' or 'getWindow(). setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);'

  • I even created a test layout here to see if I can get something here

  • Buddy, I copied your XML and added android:windowSoftInputMode="adjustResize" to the manifest and worked correctly.

Show 4 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.