How to make an Android SlidingDrawer slide out from the left?
Asked Answered
P

4

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 ?

Personable answered 16/7, 2009 at 12:49 Comment(3)
Actually I found some code that implements something similar. Blog with Screenshots: androidblogger.blogspot.com/2009/01/sliding-drawer-again.html Forum discussion: anddev.org/viewtopic.php?p=16622 Checkout code from SVN: code.google.com/p/android-misc-widgetsPersonable
i am also wanting to implement HORIZONTAL slider and i have checked the link of SVN, but there is no any project/code availableBibliofilm
Click the 'Source' tab at the top of the page and then the 'Browse' option to show the source code.Catbird
C
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.

Cuculiform answered 16/7, 2009 at 19:45 Comment(1)
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...Personable
G
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.

Gosser answered 27/6, 2012 at 14:21 Comment(9)
You are amazing man! It works fine. I searched over 3 hours to find the best solution and finally and luckily found your solution. :)Browne
Note that rotation is api level 11+ (Honecomb)Dissolve
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.Astraphobia
@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 taskBonaventura
@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.Astraphobia
@Astraphobia 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.?Bonaventura
@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. #3793694Astraphobia
@Astraphobia sorry for that. N Thanks for the link :)Bonaventura
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!Cognation
C
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.

Cuculiform answered 16/7, 2009 at 19:45 Comment(1)
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...Personable
S
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.)

Sacellum answered 28/8, 2011 at 16:47 Comment(2)
I am getting a nullpointer exception when invoking the SlidingTray. 11-13 16:41:51.980: E/AndroidRuntime(23438): Caused by: java.lang.reflect.InvocationTargetExceptionPannier
Am also getting a Null pointer exception. java.lang.NullPointerException:com.sileria.android.view.SlidingTray.onLayout(Unknown Source)Panada
R
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

Redhanded answered 26/8, 2013 at 10:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.