简体   繁体   English

如何使Android SlidingDrawer从左侧滑出?

[英]How to make an Android SlidingDrawer slide out from the left?

I'm using a slidingDrawer in my application that has its handler placed at the bottom when in portrait mode. 我在应用程序中使用了slidingDrawer ,在纵向模式下,其处理程序位于底部。 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: 我已经这样定义了布局XML:

<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 ? 有谁知道如何使其从左向右滑动?

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. 您所要做的就是将slideDrawer,内容和手柄设置为180º旋转。 You can similarly make a SlidingDrawer that descends from the top, like I did here . 您可以类似地制作从顶部下降的SlidingDrawer,就像我在这里所做的那样。

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. 请注意,我还创建了一个LinearLayout来设置为手柄,并且没有改变它的旋转角度,但是我改变了它的孩子的旋转角度。 This was to prevent a small issue I had, but everything is working fine and it's simple. 这是为了防止出现一个小问题,但是一切都很好,而且很简单。

I don't think you can, other than perhaps by grabbing the SlidingDrawer source code, making changes to it, and using your modified version. 除了通过获取SlidingDrawer源代码,对其进行更改并使用修改后的版本之外,我认为您不能这样做。 You similarly cannot make a SlidingDrawer that descends from the top. 同样,您不能创建从顶部下降的SlidingDrawer

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. 请在Android的Aniqroid开源库中查看我的SlidingTray

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

Find the download link and the documentation for SlidingTray class in the above link. 在上面的链接中找到下载链接和SlidingTray类的文档。

(Disclosure: I am the maintainer of the project.) (公开:我是项目的维护者。)

You can use the code posted in this answer: Android SlidingDrawer from top? 您可以使用以下答案中发布的代码: Android SlidingDrawer从顶部开始?

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. 所提供的解决方案具有在xml中设置Slidingdrawer的方向的功能,而且它很简单,只需要在attrs.xml中添加1个类和一些附加内容即可,并且稳定,因为它是从SDK的Androids Slidingdrawer派生的。 I also discuss why I didn't choose other popular libs/solutions found on the internet/SO. 我还将讨论为什么我没有选择在Internet / SO上找到的其他流行的lib /解决方案。

Quicklink to the gist: MultipleOrientationSlidingDrawer (source & example) @ gist 快速链接到要点: MultipleOrientationSlidingDrawer(源和示例)@要点

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM