Android : Sliding Drawer Example

      32 Comments on Android : Sliding Drawer Example

If you have lot’s of stuff to put on your screen for a single activity, you should probably go for the SlidingDrawer widget. It is very simple to use, and looks cute. Here are the steps that you need to do for bringing up the sliding drawer on your activity.

Here is a sample application displaying how to code up a sliding drawer. It’s pretty simple, and I don’t think it needs more explanation.

<SlidingDrawer android:id=”@+id/slidingDrawer1″
        android:layout_width=”fill_parent” android:layout_height=”fill_parent”
        android:topOffset=”50dip” android:handle=”@+id/handle”

The sample project sets up a Sliding Drawer at the bottom of the screen. You can change it to appear at place of the screen. You just need to change/adjust some properties of the SlidingDrawer.

  • The orientation property can be set to either “horizontal” and “vertical”
  • There are properties like “topOffset”, “bottonOffset”, “rightOffset” and “leftOffset” with which you can position your drawer anywhere.
  • With a few more changes, you can attach backgrounds/images to the whole SlidingDrawer. For example, I have added a color background to the content of the Sliding Drawer.

Update: Here is the link to the source code which shows how to cook up a simple sliding drawer.

32 thoughts on “Android : Sliding Drawer Example

  1. arun

    i have a canvas which is drawn on the ondraw method ..

    pr = new LayoutParams(320,400);

    this is how i have set the two in the content view .at first the slide drawer is on the top of canvas.. when i click to make it slide it does well. but when i click on the handler to minimise it its getting hidden beneath the canvas..but its there because as i click on the bottom region, aticipating it would be there, its getting sliding in again.. any help will be appreciated.. thanks in advance..

  2. Andrew Webber

    I got some other help from someone and I got it working by using: WindowManager.LayoutParams params = getWindow().getAttributes();

    This covers the entire parent area and I'm looking at only having the drawer slide out just far enough to show all of it's contents. Thanks for your help.

  3. Anonymous

    Thanks for your example. I add this lines and it works:

    import android.view.ViewGroup.LayoutParams;

    public class Quiz extends Activity{
    public void onCreate(Bundle savedInstanceState) {

    LayoutParams pr = new LayoutParams(320,400);
    LayoutInflater inflater = getLayoutInflater();
    View view = inflater.inflate(R.layout.drawer, null);
    getWindow().addContentView(view, pr);

  4. Sebastian

    I have a Optimus One with Android Froyo but i don`t see the slidedrawer ,i installed slidedrawer apk but is launched as a normal aplication and is empty , i need it on top of my home screen or right of the screen (right to left slide) anny sugestions or download links? if some of you know something PLEASE mail me at sebby.curta at

  5. Sebastian

    I have Optimus One running Froyo and i would like to have slidedrawer on my top of the home screen or on my right, i downloaded a zip archive wich contains manny files and installed the apk but the drawer acts as a usual aplication and when i slide it is empty ( no aplications in it), i need it to be permanently on my home screen (like dockbar is) does anny of you know how and/or a download link? is YES please mail me at sebby.curta at gmail dot com

  6. Girish

    i'm having one problem..
    i have a checbox beside sliding drawer handle.when i check it im going to lock the drawer,at the same time checkbox also gets locked i'm unable to uncheck it again..please send any answers if u have..

Leave a Reply