Search code examples
androidandroid-relativelayoutfloating-action-button

Floating action button is not floating in relative layout


So below is the layout of my loginactivity.

enter image description here

So when I click on the EditText the keyboard open ups and the floating action button doesn't come above keyboard as shown below

enter image description here

So what I want to achieve is floatingactionbutton should float up when keyboard opens as shown in below image....

enter image description here

Below is my MainActivity.xml file code...

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="80dp"
        android:layout_centerHorizontal="true"
         app:srcCompat="@drawable/ic_launcher_foreground" />

    <EditText
        android:id="@+id/etemail"
        android:layout_width="230dp"
        android:layout_height="wrap_content"
       android:layout_centerHorizontal="true"
        android:ems="10"
        android:layout_below="@+id/textView3"
        android:inputType="textPersonName" />

    <EditText
        android:id="@+id/etpw"
        android:layout_width="240dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="2dp"
        android:ems="10"
        android:inputType="textPassword"
        android:layout_centerHorizontal="true"
        android:layout_below="@+id/textView4"/>

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/floatingActionButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="16dp"
        android:layout_marginBottom="53dp"
        android:clickable="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentBottom="true"
        app:srcCompat="@drawable/ic_arrow_forward" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="50dp"
        android:layout_marginBottom="70dp"
        android:text="Forget password"
        android:layout_alignParentBottom="true"/>

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/imageView"
        android:text="@string/Signin"
        android:textSize="23dp"
        android:layout_marginLeft="80dp"
    />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView2"
        android:layout_marginLeft="80dp"
        android:layout_marginBottom="3dp"
        android:text="@string/usrname"
        app:layout_constraintBottom_toTopOf="@+id/etemail"
        app:layout_constraintStart_toStartOf="@+id/textView2" />

    <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="1dp"
        android:text="@string/pwd"
        android:layout_below="@+id/etemail"
        android:layout_marginLeft="80dp"
        />

</RelativeLayout>

Solution

  • Add Following line of code to you AndroidManifest.xml file with your specific activity.

    android:windowSoftInputMode="adjustResize"