Android Login Layout with Login Button always at Bottom

Login screen is the first impression people have about the app. We are going to make the login screen where the button will be always at the bottom of the layout and always visible even though the soft keyboard is in action. Now let’s see how it works.

To make the layout we will use linear layout as parent layout and in that we will have one scroll layout and one linear layout. By using the weight parameter we will divide the screen, so that the button at the bottom should always be there. With layout_weight we can specify a size ratio between multiple views.

Below is the structure of our layout.

layout

The layout is below:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
     xmlns:android="http://schemas.android.com/apk/res/android"     
     xmlns:tools="http://schemas.android.com/tools"     
     android:id="@+id/activity_main"     
     android:layout_width="match_parent"     
     android:layout_height="match_parent"     
     tools:context="in.blogspot.pawandubeysblog.layoutdesign.MainActivity"     
     android:orientation="vertical">         
     <ScrollView             
          android:layout_width="match_parent"             
          android:layout_height="wrap_content"             
          android:layout_weight="9">             
          <LinearLayout                 
               android:layout_width="match_parent"                 
               android:layout_height="wrap_content"                 
               android:orientation="vertical"                 
               android:paddingLeft="20dp"                 
               android:paddingRight="20dp"                 
               android:paddingBottom="20dp"                 
               android:paddingTop="20dp">                 
               <EditText                     
                    android:layout_width="match_parent"                     
                    android:layout_height="wrap_content"                     
                    android:inputType="text"                     
                    android:hint="Username"/>                 
               <EditText                     
                    android:layout_width="match_parent"                     
                    android:layout_height="wrap_content"                     
                    android:inputType="textPassword"                     
                    android:hint="Password"/>             
          </LinearLayout>         
     </ScrollView>        
     <LinearLayout         
          android:layout_width="match_parent"         
          android:layout_height="wrap_content"         
          android:layout_weight="0"         
          android:layout_gravity="bottom"         
          android:orientation="vertical"         
          android:paddingLeft="20dp"         
          android:paddingRight="20dp"         
          android:paddingBottom="20dp">         
         <Button             
              android:id="@+id/setup_macroSavebtn"             
              android:layout_width="match_parent"             
              android:layout_height="wrap_content"             
              android:text="Save"             
              android:background="#0099e5"             
              android:textColor="@android:color/background_light" />     
     </LinearLayout>
</LinearLayout>

 

The output will be as shown below:

loginlayoutoutput