SlidingDrawer
A custom View implementing the bottom sheet pattern.
This ViewGroup can have only 2 children. The 1st one is the non slidable view ; the 2nd is the slidable view, which can slide over the non slidable view.
The substantial difference from all other implementations is that in this case is easy to position the slidable view relative to the non slidable view.
In other implementations the only way to control the position of the slidable view, when collapsed, is by using a peek factor.
Here instead the slidable view is placed exactly below the non slidable view, just like in a vertical LinearLayout. The slidable view is conceptually part of the hierarchy and it's not above it.
Download the sample app here
Apps using this library: Shuffly
Download
Add this to you project-level build.gradle
:
allprojects {
repositories {
...
maven {
url "https://jitpack.io"
}
}
}
Add this to your module-level build.gradle
:
dependencies {
compile 'com.github.PierfrancescoSoffritti:SlidingDrawer:0.10'
}
Usage
<com.pierfrancescosoffritti.slidingdrawer.SlidingDrawer
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:elevation="4dp" >
<LinearLayout
android:id="@id/non_slidable_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="100dp"
android:text="non slidable content" />
</LinearLayout>
<FrameLayout
android:id="@id/slidable_view"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/drag_view"
android:layout_width="match_parent"
android:layout_height="100dp"
android:text="drag me"
android:clickable="true" />
</FrameLayout> </com.pierfrancescosoffritti.slidingdrawer.SlidingDrawer>
It's important to set the id attribute to android:id="@id/non_slidable_view"
for the non slidable view and to android:id="@id/slidable_view"
for the slidable view.
When you use this ViewGroup remember to always add a drag view slidingDrawer.setDragView(view);
The drag view is the only surface from which the slidable view can be dragged. The drag view must be clickable.
In case the slidable view has different views when collapsed ( collapsed view) or expanded ( expanded view), and the collapsed view isn't a List (or equivalent), it should have the id android:id="@id/sliding_drawer_collapsed_view"
, so the SlidingDrawer
can adjust the view's paddingBottom to prevent its content from going offscreen.