Android SlidingDrawer on top?

Is there a way to make the slide slider from top to bottom?

+26
android
Sep 12 '10 at 17:48
source share
4 answers

The SlidingDrawer class does not allow this by default. You can use the Panel class from here to get something very similar: http://code.google.com/p/android-misc-widgets/

http://www.ohloh.net/p/android-misc-widgets

+7
Sep 12 '10 at 17:55
source share

I found an easy way to do this. All you have to do is set the rotation to 180º for the sliding device, contents and handle. This is easier to understand with an example, so look what I did:

First I will show you my old SlidingDrawer, from the bottom up.

 <SlidingDrawer xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/slidingDrawer" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:gravity="center_horizontal" android:handle="@+id/handle" android:content="@+id/content"> <ImageView android:id="@+id/handle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher" /> <ImageView android:id="@+id/content" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#FF0000" android:src="@drawable/ic_launcher" /> </SlidingDrawer> 

Now let's look at the changes I made by setting the rotation to 180º

 <SlidingDrawer xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/slidingDrawer" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:gravity="center_horizontal" android:handle="@+id/handle" android:content="@+id/content" android:rotation="180"> <LinearLayout android:id="@+id/handle" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageView android:id="@+id/imageView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher" android:rotation="180" /> </LinearLayout> <ImageView android:id="@+id/content" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#FF0000" android:src="@drawable/ic_launcher" android:rotation="180" /> </SlidingDrawer> 

Note that I also created LinearLayout to set as a descriptor and did not change its rotation, but I changed its birth. This was to prevent a small problem that I had, but everything works fine, and it's simple.

+30
Jun 27 '12 at 13:45
source share

I was very unhappy with the solutions offered here:

  • The Panel class from http://code.google.com/p/android-misc-widgets/ was really unintuitive to use, and also had bugs and visual glitches (unsuitable for productive use) and no documents at all
  • SlidingTray class from http://aniqroid.sileria.com/doc/api/ was nested in a lib that needed too much dependency, and for me I didn't get it to work all
  • using android:rotation="180" requires API level 11 and my goal is 10.

(no violation for the respective developers, trying to be objective here)

So, my solution was to extract SlidingTray from this lib http://aniqroid.sileria.com/doc/api/ (Ahmed Shaquil) and edited it a bit, as it had some quirks needed for use in Ahmed lib. SlidingTray based on Androids own SlidingDrawer , so I think it is stable. My change consists of 1 class, which I called MultipleOrientationSlidingDrawer and you have to add declare-styleables to your attrs.xml. In addition, it has almost the same usage as SlidingDrawer with the optional “orientation” attribute.

Check this out: MultipleOrientationSlidingDrawer (source and example) @gist

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

 <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 loans are transferred to the respective developers. I have not tested this solution extensively, it works fine with TOP and BOTTOM installed in XML. I did not try to use it programmatically.

+7
Aug 20 '13 at 17:23
source share

I had to do the same for one of my projects, and in the end I wrote my own widget. I named it SlidingTray is now part of my open Aniqroid library.

http://aniqroid.sileria.com/doc/api/ (Look at the downloads below or use the Google code project to see additional download options: http://code.google.com/p/aniqroid/downloads/list )

The class documentation is here: http://aniqroid.sileria.com/doc/api/com/sileria/android/view/SlidingTray.html

+6
Jul 29 '11 at 18:17
source share



All Articles