21
votes

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 ?

4
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-widgets – Vidar Vestnes
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
Click the 'Source' tab at the top of the page and then the 'Browse' option to show the source code. – Adil Hussain

4 Answers

30
votes

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.

6
votes

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.

1
votes

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.)

0
votes

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