Open In App

Sliding Up Screen in Android

Last Updated : 23 Feb, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

Sliding Up Screen is another common feature that we see in most of the apps. This Sliding Up Screen can be used for displaying some content after clicking the button or to display Menu. Using this Sliding Up Screen in our App improves the User Experience. In this article, we are going to see how to implement the Sliding Up Screen in Android. A sample GIF is given below to get an idea about what we are going to do in this article. 

Sliding Up Screen in Android Sample GIF

Applications of Sliding Up Screen

  • Sliding Up Screen can be used to show some content after clicking the button in another attractive form.
  • This Sliding Up Screen can also be used to display additional Menu Options.
  • Using Sliding Up Screen in our app improves User Experience.

Attributes of Sliding Up Screen

Attributes

Description

layout_width Used to give layout Width.
layout_height Used to give layout height.
gravity Used to give gravity.
umanoPanelHeight Used to give height to the panel.
umanoShadowHeight Used to display shadow height.

Step by Step Implementation

Step 1: Create a New Project

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Java as the programming language.

Step 2: Add dependency of Sliding Up Screen library in build.gradle file

Then Navigate to Gradle scripts and then to build.gradle(Module) level. Add below line in build.gradle file in the dependencies section.

implementation ‘com.sothree.slidinguppanel:library:3.4.0’

now click on Sync now it will sync your all files in build.gradle().

Step 3: Create a new Sliding Up Screen in your activity_main.xml file

Navigate to the app > res > layout to open the activity_main.xml file. Below is the code for the activity_main.xml file. 

XML




<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="16dp"
    android:paddingTop="16dp"
    android:paddingRight="16dp"
    android:paddingBottom="16dp"
    tools:context=".MainActivity">
  
    <!--Sliding Up Screen-->
    <com.sothree.slidinguppanel.SlidingUpPanelLayout 
        xmlns:sothree="http://schemas.android.com/apk/res-auto"
        android:id="@+id/sliding_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="bottom"
        sothree:umanoPanelHeight="68dp"
        sothree:umanoShadowHeight="4dp">
  
        <!--First Screen-->
        <include
            layout="@layout/layout_first"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
  
        <!--Second Screen-->
        <include
            layout="@layout/layout_second"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </com.sothree.slidinguppanel.SlidingUpPanelLayout>
      
</RelativeLayout>


Step 4: Create a screen1 and screen 2 in the layout folder

Navigate to the app > res > layout and create layout_first.xml and layout_second.xml file in the layout folder. Follow the code given below.

layout_first.xml file:

XML




<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:gravity="center"
    android:orientation="vertical">
  
    <!--Text view to display text-->
    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="This is First Screen" />
      
    <!--Button for click-->
    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Click" />
      
</LinearLayout>


layout_second.xml file:

XML




<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:gravity="center"
    android:orientation="vertical">
  
    <!--Text view to display text-->
    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="This is Second Screen" />
  
    <!--Button for click-->
    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Click Again" />
      
</LinearLayout>


Now click on the run option it will take some time to build Gradle. After that, you will get output on your device as given below.

Output:



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads