21

I'm using a slidingDrawer in my application that has its handler placed at the bottom when in portrait mode. When the user switches to landscape mode (widescreen) I would like to have the handler located on the left. When I change the orientation from vertical to horizontal, the handler is placed on the right.

I have defined my layout XML like this:

<SlidingDrawer
    android:id="@+id/l_drawer"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:handle="@+id/l_handle"
    android:content="@+id/l_content"
    android:orientation="horizontal"
    android:layout_gravity="left"
    >

Anyone have an idea for how to make it slide from left to right ?

Jeremy Logan
  • 47,151
  • 38
  • 123
  • 143
Vidar Vestnes
  • 42,644
  • 28
  • 86
  • 100
  • Actually I found some code that implements something similar. Blog with Screenshots: http://androidblogger.blogspot.com/2009/01/sliding-drawer-again.html Forum discussion: http://www.anddev.org/viewtopic.php?p=16622 Checkout code from SVN: http://code.google.com/p/android-misc-widgets/ – Vidar Vestnes Jul 17 '09 at 12:19
  • i am also wanting to implement HORIZONTAL slider and i have checked the link of SVN, but there is no any project/code available – Paresh Mayani Sep 25 '10 at 07:32
  • Click the 'Source' tab at the top of the page and then the 'Browse' option to show the source code. – Adil Hussain Dec 27 '11 at 15:27

4 Answers4

30

I've found a simple way to do that. All you have to do is to set the rotation of 180º for the slidingDrawer, the content and the handle. You can similarly make a SlidingDrawer that descends from the top, like I did here.

Look at my examples here, first from right to left, to be able to see the differences.

<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="horizontal"
    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 look what I changed to make it sliding out from the left.

<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="horizontal"
    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 a LinearLayout to set as handle, and didn't change it's rotation, but I changed the rotation of it's child. This was to prevent a small issue I had, but everything is working fine and it's simple.

Community
  • 1
  • 1
Leandroid
  • 1,997
  • 2
  • 17
  • 19
  • You are amazing man! It works fine. I searched over 3 hours to find the best solution and finally and luckily found your solution. :) – Hesam Jul 11 '12 at 08:47
  • 4
    Note that rotation is api level 11+ (Honecomb) – Parth Mehrotra Dec 26 '12 at 03:43
  • 1
    Also note that SlidingDrawer was deprecated in API 17 (Android 4.2) so it's probably better to future proof-yourself and migrate away from SlidingDrawer. – spaaarky21 Feb 14 '13 at 21:44
  • @spaaarky21, i want to say that its not working in 2.2 and 4.2 also so would you please provide me any solution to do this task – TheLittleNaruto Jul 25 '13 at 05:14
  • @Kumar Without seeing your code, I couldn't say why it isn't working for you in 4.2. As for 2.2, if you read Parth Mehrotra's comment above, you will see that rotation wasn't supported until Android 3. Like I said, it's probably better to migrate away from SlidingDrawer entirely since you can't rotate a drawer until 3.0 and SlidingDrawer was deprecated in 4.2. There are other questions on StackOverflow that discuss alternatives. – spaaarky21 Jul 25 '13 at 15:57
  • @spaaarky21 Yes you're right . so is there any other way to do the same. I want to make incoming call screen where I want to put slide-able receiving and rejecting layout. Could you please refer me something.? – TheLittleNaruto Jul 26 '13 at 05:38
  • @Kumar StackOverflow is not a forum. Please don't use comments to ask new questions. If you need recommendations for an alternative to SlidingDrawer, search. The question has been asked numerous times. If you don't find what you are looking for, start a new question. This one has a few suggestions though. http://stackoverflow.com/questions/3793194/android-making-sliding-drawer-to-slide-from-left-to-right – spaaarky21 Jul 26 '13 at 15:54
  • @spaaarky21 sorry for that. N Thanks for the link :) – TheLittleNaruto Jul 28 '13 at 10:20
  • works brilliant in android 4.4 if you put the content of the sliding drawer in a seperate layout and rotate this layout by 180 degrees! – dy_ Sep 30 '14 at 11:52
6

I don't think you can, other than perhaps by grabbing the SlidingDrawer source code, making changes to it, and using your modified version. You similarly cannot make a SlidingDrawer that descends from the top.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • After more googling around, I still havn't found any examples or ways to do this, so yes, i agree, there is no way to do this with the android sdk... – Vidar Vestnes Jul 17 '09 at 06:55
1

I have rewritten a class to that and made it part of my open source library. It took me almost a week to get it right. Please check out my SlidingTray in Aniqroid open source library for Android.

http://aniqroid.sileria.com/doc/api

Find the download link and the documentation for SlidingTray class in the above link.

(Disclosure: I am the maintainer of the project.)

Sileria
  • 15,223
  • 4
  • 49
  • 28
  • 1
    I am getting a nullpointer exception when invoking the SlidingTray. 11-13 16:41:51.980: E/AndroidRuntime(23438): Caused by: java.lang.reflect.InvocationTargetException – vandus Nov 13 '13 at 15:44
  • Am also getting a Null pointer exception. java.lang.NullPointerException:com.sileria.android.view.SlidingTray.onLayout(Unknown Source) – Sathesh Jun 25 '14 at 06:42
0

You can use the code posted in this answer: Android SlidingDrawer from top?

The provided solution features setting the orientation of the Slidingdrawer in xml also it's simple requiring only 1 class and some additions in attrs.xml and stable since it's derived from Androids Slidingdrawer from SDK. I also discuss why I didn't choose other popular libs/solutions found on the internet/SO.

Quicklink to the gist: MultipleOrientationSlidingDrawer (source & example) @ gist

Community
  • 1
  • 1
Patrick
  • 33,984
  • 10
  • 106
  • 126