Implement Sliding Drawer like functionality

132 Views Asked by At

I wanted to add a Sliding Drawer to one of my activities, but saw that it was deprecated since API 17.

What I'm interested in doing something similar to this one from androhub.

My drawer/activity/fragment that pops up has only buttons inside. I need that handle button and I want the drawer to go up until the handle button hits the top of the screen.

Can you point out what I can use to achieve this?

3

There are 3 best solutions below

0
Gavin Wright On

BottomSheet will open from the bottom. DrawerLayout will open from the side.

0
Samir Bhatt On

You can implement the same functionality by using BottomSheetDialog.

0
Okeme Christian On

You can achieve this by using the AndroidSlidingUpPanel package by Umano

Importing the Library

dependencies {
  repositories {
     mavenCentral()
  }
  implement 'com.sothree.slidinguppanel:library:3.4.0'
}

Include com.sothree.slidinguppanel.SlidingUpPanelLayout as the root element in your activity layout. The layout must have gravity set to either top or bottom. Make sure that it has two children. The first child is your main layout. The second child is your layout for the sliding up panel. The main layout should have the width and the height set to match_parent. The sliding layout should have the width set to match_parent and the height set to either match_parent, wrap_content or the max desireable height. If you would like to define the height as the percetange of the screen, set it to match_parent and also define a layout_weight attribute for the sliding view. By default, the whole panel will act as a drag region and will intercept clicks and drag event

e.g xml

<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">

<TextView
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:gravity="center"
   android:text="Main Content"
   android:textSize="16sp" />

<TextView
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:gravity="center|top"
   android:text="The Awesome Sliding Up Panel"
   android:textSize="16sp" />
</com.sothree.slidinguppanel.SlidingUpPanelLayout>