Android SlidingDrawer 从顶部?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3695856/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android SlidingDrawer from top?
提问by stefos
Is there any way to make the drawer slide from top to bottom?
有什么办法可以让抽屉从上往下滑动吗?
采纳答案by Computerish
The default SlidingDrawer
class doesn't allow this. You can use the Panel
class from here to get something very similar though:
http://code.google.com/p/android-misc-widgets/
默认SlidingDrawer
类不允许这样做。你可以使用Panel
这里的类来获得非常相似的东西:http:
//code.google.com/p/android-misc-widgets/
回答by Leandroid
I've found a simple way to do that. All you have to do is to set the rotation of 180o for the slidingDrawer, the content and the handle. It's easier to understand with an example, so look what I've done:
我找到了一个简单的方法来做到这一点。你所要做的就是为slidingDrawer、内容和手柄设置180o的旋转。用一个例子更容易理解,所以看看我做了什么:
First, I'll show you my old SlidingDrawer, from bottom to top.
首先,我将向您展示我的旧 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>
Now look at the changes I made, setting the rotation of 180o
现在看看我所做的更改,设置旋转 180o
<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>
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.
请注意,我还创建了一个 LinearLayout 来设置为句柄,并没有改变它的旋转,但是我改变了它的子级的旋转。这是为了防止我遇到的一个小问题,但一切正常,而且很简单。
回答by Patrick Favre
I was very unsatisfied with the solutions provided here:
我对这里提供的解决方案非常不满意:
- The
Panel
class from http://code.google.com/p/android-misc-widgets/was really unintuitive to use and also had bugs and visual glitches (unusable for productive use) and no docs at all SlidingTray
class from http://aniqroid.sileria.com/doc/api/was nested in a lib needing too much dependency and for me I did not get it to work at all- using
android:rotation="180"
requires API Level 11, and my target is 10.
Panel
来自http://code.google.com/p/android-misc-widgets/的课程使用起来非常不直观,并且还有错误和视觉故障(无法用于生产用途),而且根本没有文档SlidingTray
来自http://aniqroid.sileria.com/doc/api/ 的类嵌套在需要太多依赖的库中,对我来说我根本没有让它工作- 使用
android:rotation="180"
需要 API 级别 11,我的目标是 10。
(no offense to the respective devs, trying to be objective here)
(无意冒犯相应的开发人员,在这里尽量保持客观)
So my solution was to extract SlidingTrayfrom this lib http://aniqroid.sileria.com/doc/api/(by Ahmed Shakil) and
refactored it a bit since it had some quirks needed to be used within Ahmed's lib. SlidingTray
is based on Androids own SlidingDrawer
, so I guess it is stable. My modification consists of 1 class which I called MultipleOrientationSlidingDrawer
and
you have to add declare-styleables in your attrs.xml. Other than that it has pretty much the same usage as SlidingDrawerwith the additional "orientation" attribute..
所以我的解决方案是从这个库http://aniqroid.sileria.com/doc/api/(由 Ahmed Shakil)中提取SlidingTray并对其进行重构,因为它有一些需要在 Ahmed 库中使用的怪癖。是基于安卓自己的,所以我猜它是稳定的。我的修改包括我调用的 1 个类,您必须在 attrs.xml 中添加声明样式。除此之外,它
与带有附加“方向”属性的SlidingDrawer 的用法几乎相同。SlidingTray
SlidingDrawer
MultipleOrientationSlidingDrawer
Check it out: MultipleOrientationSlidingDrawer (source & example) @ gist
检查一下:MultipleOrientationSlidingDrawer(来源和示例)@gist
Here is a usage example (also provided in the 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>
Disclaimer: All the credits go to respective dev. I did not test this solution extensivly, it works great with TOP and BOTTOM set in XML. I did not try to use it programmatically.
免责声明:所有学分归各自的开发人员所有。我没有广泛地测试这个解决方案,它在 XML 中设置 TOP 和 BOTTOM 时效果很好。我没有尝试以编程方式使用它。
回答by Sileria
I had to do the same for one of my projects and I ended up writing my own widget for this. I called it SlidingTrayis now part of my open source Aniqroidlibrary.
我不得不为我的一个项目做同样的事情,我最终为此编写了自己的小部件。我称之为SlidingTray现在是我的开源Aniqroid库的一部分。
http://aniqroid.sileria.com/doc/api/(Look for downloads at the bottom or use google code project to see more download options: http://code.google.com/p/aniqroid/downloads/list)
http://aniqroid.sileria.com/doc/api/(在底部寻找下载或使用谷歌代码项目查看更多下载选项:http: //code.google.com/p/aniqroid/downloads/list)
The class documentation is here: http://aniqroid.sileria.com/doc/api/com/sileria/android/view/SlidingTray.html
类文档在这里:http: //aniqroid.sileria.com/doc/api/com/sileria/android/view/SlidingTray.html