Android SlidingDrawer从顶部?

ste*_*fos 27 android

有没有办法让抽屉从上到下滑动?

Lea*_*oid 31

我找到了一种简单的方法.您所要做的就是为slidingDrawer,内容和句柄设置180º的旋转.通过示例更容易理解,所以看看我做了什么:

首先,我将从底部到顶部向您展示我的旧SlidingDrawer.

<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>
Run Code Online (Sandbox Code Playgroud)

现在看看我所做的改变,设置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>
Run Code Online (Sandbox Code Playgroud)

请注意,我还创建了一个LinearLayout来设置为句柄,并没有改变它的旋转,但我更改了它的子项的旋转.这是为了防止我遇到的一个小问题,但一切都很好,而且很简单.

  • 注意`android:rotation`是API Level 11(Android 3.0). (3认同)

Com*_*ish 7

默认SlidingDrawer类不允许这样做.您可以使用Panel此处的类来获得非常相似的内容:http: //code.google.com/p/android-misc-widgets/

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


pat*_*ckf 7

我对这里提供的解决方案非常不满意:

(对各自的开发者没有冒犯,试图在这里客观)

所以我的解决方案是从这个lib http://aniqroid.sileria.com/doc/api/(Ahmed Shakil)中提取SlidingTray并重构一下,因为它需要在Ahmed的lib中使用一些怪癖.是基于Androids自己的,所以我猜它是稳定的.我的修改包括我调用的一个类,你必须在attrs.xml中添加declare-styleables.除此之外,它具有与SlidingDrawer几乎相同的用法以及 额外的"orientation"属性.SlidingTraySlidingDrawerMultipleOrientationSlidingDrawer

看看:MultipleOrientationSlidingDrawer(来源和示例)@gist

这是一个用法示例(也在要点中提供)

<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>
Run Code Online (Sandbox Code Playgroud)

免责声明:所有学分都归各自开发.我没有直接测试这个解决方案,它在用XML设置的TOP和BOTTOM时效果很好.我没有尝试以编程方式使用它.


Sil*_*ria 6

我必须为我的一个项目做同样的事情,最后我为此编写了自己的小部件.我称之为SlidingTray现在是我的开源Aniqroid库的一部分.

http://aniqroid.sileria.com/doc/api/ (查看底部的下载或使用谷歌代码项目查看更多下载选项:http://code.google.com/p/aniqroid/downloads/list)

课程文档在这里:http://aniqroid.sileria.com/doc/api/com/sileria/android/view/SlidingTray.html

  • 糟糕,看起来我忘记了`Kit.init()`...现在工作得很好! (2认同)