2010-09-12 50 views

回答

7

默认SlidingDrawer类不允许这样做。您可以使用Panel类从这里得到一些非常相似,但: http://code.google.com/p/android-misc-widgets/

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

+1

你有没有在那里工作的面板?我很难整合这个面板,虽然这看起来很酷。我的问题在这里,如果有人可以查看它http://code.google.com/p/android-misc-widgets/issues/detail?id=9错误说“二进制XML文件行#15:内容属性是必需的,必须提及有效的孩子。“ – OneWorld 2010-11-04 09:06:29

+0

我不得不将面板小部件包装到一个框架布局以使其工作 – OneWorld 2010-11-25 15:04:46

+1

顶部滴管有一个不需要的行为:下面的内容被移动到底部。我是这样修复的:<其他下面的东西/> OneWorld 2010-12-02 20:06:58

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

+0

我试过这个,但是当我使用xml示例实现它时,我在'com.sileria.android.Resource.getIdentifier'处得到了'nullpointer exception'。愿意使用这个。 – Peterdk 2011-08-31 11:25:57

+2

糟糕,看起来像我忘了'Kit.init()'...现在伟大的工程! – Peterdk 2011-08-31 11:34:08

+0

此外,如果您从文档中复制/粘贴XML示例,它是'com.sileria.android.view.SlidingTray'而不是'com.sileria.android.SlidingTray' – Fr4nz 2013-06-17 13:16:31

30

我已经找到了一种简单的方法来做到这一点。您所要做的就是为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> 

现在看看我所做的更改,设定的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> 

请注意,我还创建了一个的LinearLayout设置为手柄,并没有改变它的旋转中是旋转的,但我改变它的孩子的旋转。这是为了防止我有一个小问题,但一切工作正常,很简单。

+3

注意'android:rotation'是API Level 11(Android 3.0)。 – azdev 2012-07-25 02:37:01

+0

一个不错的...但是怎么样 2012-10-09 12:39:40

+0

我没有找到一个解决方案,在API Level 11 – Leandroid 2012-10-12 16:15:00

7

我很不满意这里提供的解决方案:

(没有冒犯到各自的开发者,试图在这里的目标)

所以我的解决办法是从这个LIB http://aniqroid.sileria.com/doc/api/(由艾哈迈德·沙基勒)和 提取SlidingTray重构它一下,因为它有一些怪癖需要在Ahmed的lib中使用。 SlidingTray是基于Android自己的SlidingDrawer,所以我想它是稳定的。我的修改由1个类组成,我称其为MultipleOrientationSlidingDrawer和 ,您必须在您的attrs.xml中添加declare-styleables。除此之外,它与使用附加“方向”属性的SlidingDrawer 具有几乎相同的用法。

检查出来:MultipleOrientationSlidingDrawer (source & example) @ 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> 

免责声明:所有的学分转到相应的开发。我没有广泛地测试这个解决方案,它的工作原理很好 在XML中设置了TOP和BOTTOM。我没有尝试以编程方式使用它。

+0

这是好的,但你看到动画的问题?您在移动时是否找到了闪烁视图的解决方案? – Vetalll 2013-09-30 11:55:30

+0

我的确有闪烁的http://code.google.com/p/android-misc-widgets/,但与此apporach(到目前为止)的指示 – for3st 2013-10-21 14:45:12

+0

是否有可能使'FrameLayout' content_c'不能占用所有可用空间,因为我看到它将所有东西都拉下来,即使我设置了'android:layout_height =“wrap_content”' – Erik 2017-08-15 13:54:24