Widget: SlidingDrawer top to bottom

My android experiments continue…
In the last project I had to implement a SlidingDrawer which comes from top and left. The problem was that the default widget does not support all the directions, but only bottom to top and right to left.

That’s why I grabbed the SlidingDrawer source code and modified it in order to allow any direction ( defined as styleable in attrs.xml ). The only problem using custom styleable xml is that if you want to use this widget as library you need to include in the main project also the attrs.xml file as well.. a bit frustrating.

Anyway this is just the sample xml how to include the widget:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
   <view class="it.sephiroth.demo.slider.widget.MultiDirectionSlidingDrawer"
     xmlns:my="http://schemas.android.com/apk/res/it.sephiroth.demo.slider"
     android:id="@+id/drawer"
     my:direction="topToBottom"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     my:handle="@+id/handle"
     my:content="@+id/content">
      <include android:id="@id/content"
        layout="@layout/pen_content" />
      <imageview android:id="@id/handle"
        android:layout_width="wrap_content"
        android:layout_height="40px"
        android:src="@drawable/sliding_drawer_handle_bottom" />
   </view>
</relativelayout>

Btw If you’re interest, here you can find the full source code of the widget including a running application:

SlidingDrawer Demo 

* Updated the code thanks to Maciej Ciemięga.

Lead Android developer at Aviary and New Yorker since 2011. Mixed marketing and artistic background with more than 10 years of experience with Flash actionscript and python before switching to android development.