Skip to main content
  1. Articles/

Q: Android SlidingDrawer from top?

This was originally posted as an answer to the question "Android SlidingDrawer from top?" on stackoverflow.com.
7 upvotes
34k views

I was very unsatisfied with the solutions provided here:

(no offense to the respective devs, trying to be objective here)

So my solution was to extract SlidingTray from this lib http://aniqroid.sileria.com/doc/api/ (by Ahmed Shakil) and refactored it a bit since it had some quirks needed to be used within Ahmed’s lib. SlidingTray is based on Androids own SlidingDrawer, so I guess it is stable. My modification consists of 1 class which I called MultipleOrientationSlidingDrawer and you have to add declare-styleables in your attrs.xml. Other than that it has pretty much the same usage as SlidingDrawer with the additional “orientation” attribute..

Check it out: MultipleOrientationSlidingDrawer (source & example) @ gist

Here is a usage example (also provided in the gist)

<your.app.MultipleOrientationSlidingDrawer
        xmlns:custom="http://schemas.android.com/apk/res-auto/your.app"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        custom:handle="@+id/handle_c"
        custom:content="@+id/content_c"
        custom:orientation="top">
        <RelativeLayout
            android:id="@id/handle_c"
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:background="#333333">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:text="Handle Text"
                android:gravity="left|center_vertical"/>
        </RelativeLayout>

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@id/content_c"
            android:background="#555555">

            <ListView
                android:id="@+id/listview_credits"
                android:layout_width="match_parent"
                android:layout_height="match_parent"/>
        </FrameLayout>
    </your.app.MultipleOrientationSlidingDrawer>

Disclaimer: All the credits go to respective dev. I did not test this solution extensively, it works great with TOP and BOTTOM set in XML. I did not try to use it programmatically.