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.

  • Pingback: Transparent View in android : Android Community - For Application Development()

  • Philip

    the clicklistener isn’t working properly. I am using leftToRight direction and already changed the c4 = ( !mExpanded && handleRight > mTopOffset + mHandleWidth – mTapThreshold );
    And most of the times the click listener to open doesn’t work. How i can i solve this?

  • http://www.facebook.com/qassim.jaefer Kasem Jaffer

    How do i make the drawer not Translucent?

  • ajay

    Have more than 15 menu items, how do I enable scrolling within the drawer when it is open? can someone please help

  • vabhav singh

    great example for sliding drawer support with all api version

  • Pingback: Android: SlidingDrawer with bottomOffset and content visible()

  • Pingback: 四个方向上的SlidingDrawer - 移动端开发 - 开发者()

  • priya

    Thanks alot.I searched so many times of this functionality.This url is not working from 2 weeks.Today its working.Now i am very happy.

  • Khurram

    Hi I really appreciate your work, really good example, I have small concern. When I used this drawer open, it open with hanging but when I close, it close smooth, I want open and close smoothly. here are my constant values private static final int TAP_THRESHOLD = 1;

    private static final float MAXIMUM_TAP_VELOCITY = 110.0f;

    private static final float MAXIMUM_MINOR_VELOCITY = 110.0f;

    private static final float MAXIMUM_MAJOR_VELOCITY = 110.0f;

    private static final float MAXIMUM_ACCELERATION = 195.0f;

    private static final int VELOCITY_UNITS = 1000;

    private static final int MSG_ANIMATE = 1000;

    private static final int ANIMATION_FRAME_DURATION = 1000 / 60;