Android 导航抽屉(Google+ 与 YouTube)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11377472/
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
Navigation Drawer (Google+ vs. YouTube)
提问by EGHDK
Does anyone know how to implement a sliding menu like some of the top apps of today?
有谁知道如何实现像当今一些顶级应用程序一样的滑动菜单?
Other Stack Overflow questionshaven't had any answers on how to do this, so I'm trying to gather as much info to help out others. All the applications I mention below do a great job of implementing the slide menu.
其他 Stack Overflow问题没有关于如何做到这一点的任何答案,所以我试图收集尽可能多的信息来帮助其他人。我在下面提到的所有应用程序都在实现幻灯片菜单方面做得很好。
1. Google Plus (as of 7/7/12)
1. Google Plus(截至 12 年 7 月 7 日)
You can only go from the first screen to the second screen by clicking the G+ logo in the upper left hand corner. Notice that the entire screen moves from it's position and get's nudged to the right side of the screen (including the action bar). To get back to the first screen you can either slide the right side back into focus or you can click the G+ icon again.
您只能通过单击左上角的 G+ 徽标从第一个屏幕转到第二个屏幕。请注意,整个屏幕从它的位置移动,并被轻推到屏幕的右侧(包括操作栏)。要返回第一个屏幕,您可以将右侧滑回焦点,也可以再次单击 G+ 图标。
2. YouTube (as of 7/7/12)
2. YouTube(截至 12 年 7 月 7 日)
You can go from the first screen to second screen using two methods. Either click the YouTube logo in the upper left, or you can use a swipe gesture to move it to the right. This is already different from the G+ app. Secondly, you can see that the action bar stays put (Unlike G+). Lastly, to get the original screen back it works just like G+.
您可以使用两种方法从第一个屏幕转到第二个屏幕。单击左上角的 YouTube 徽标,或者您可以使用滑动手势将其向右移动。这已经不同于 G+ 应用了。其次,您可以看到操作栏保持不变(与 G+ 不同)。最后,要恢复原始屏幕,它就像 G+ 一样工作。
采纳答案by Alex Lockwood
Edit #3:
编辑#3:
The Navigation Drawer pattern is officially described in the Android documentation!
Navigation Drawer 模式在 Android 文档中有正式的描述!
Check out the following links:
查看以下链接:
Edit #2:
编辑#2:
Roman Nurik (an Android design engineer at Google) has confirmed that the recommended behavior is to not move the Action Bar when opening the drawer (like the YouTube app). See this Google+ post.
Roman Nurik(Google 的 Android 设计工程师)已确认推荐的行为是在打开抽屉时不要移动操作栏(如 YouTube 应用程序)。请参阅此Google+ 帖子。
Edit #1:
编辑#1:
I answered this question a while ago, but I'm back to re-emphasize that Prixing has the best fly-out menu out there... by far. It's absolutely beautiful, perfectly smooth, and it puts Facebook, Google+, and YouTube to shame. EverNote is pretty good too... but still not as perfect as Prixing. Check out this series of postson how the flyout menu was implemented (from none other than the head developer at Prixing himself!).
不久前我回答了这个问题,但我再次强调,Prixing 拥有最好的弹出菜单......到目前为止。它非常漂亮,非常流畅,让 Facebook、Google+ 和 YouTube 相形见绌。EverNote 也很不错……但仍然不如 Prixing 完美。查看有关如何实现弹出菜单的这一系列帖子(来自 Prixing 的首席开发人员本人!)。
Original Answer:
原答案:
Adam Powell and Richard Fulcher talk about this at 49:47 - 52:50in the Google I/O talk titled "Navigation in Android".
Adam Powell 和 Richard Fulcher 于49:47 - 52:50在题为“Android 导航”的 Google I/O 演讲中讨论了这一点。
To summarize their answer, as of the date of this posting the slide out navigation menu is notofficially part of the Android application design standard. As you have probably discovered, there's currently no native support for this feature, but there was talk about making this an addition to an upcoming revision of the support package.
总结一下他们的回答,截至本文发布之日,滑出式导航菜单尚未正式成为 Android 应用程序设计标准的一部分。您可能已经发现,目前没有对此功能的本地支持,但有人讨论将其添加到即将到来的支持包修订版中。
With regards to the YouTube and G+ apps, it does seem odd that they behave differently. My best guess is that the reason the YouTube app fixes the position of the action bar is,
关于 YouTube 和 G+ 应用程序,它们的行为不同似乎很奇怪。我最好的猜测是 YouTube 应用固定操作栏位置的原因是,
One of the most important navigational options for users using the YouTube app is search, which is performed in the
SearchView
in the action bar. It would make sense to make the action bar static in this regard, since it would allow the user to alwayshave the option to search for new videos.The G+ app uses a
ViewPager
to display its content, so making the pull out menu specific to the layout content (i.e. everything under the action bar) wouldn't make much sense. Swiping is supposed to provide a means of navigating between pages, not a means of global navigation. This might be why they decided to do it differently in the G+ app than they did in the YouTube app.On another note, check out the Google Play app for another version of the "pull out menu" (when you are at the left most page, swipe left and a pull out, "half-page" menu will appear).
对于使用 YouTube 应用的用户来说,最重要的导航选项之一是搜索,它
SearchView
在操作栏中执行。在这方面,将操作栏设为静态是有意义的,因为它允许用户始终可以选择搜索新视频。G+ 应用程序使用 a
ViewPager
来显示其内容,因此针对布局内容(即操作栏下的所有内容)制作特定于拉出的菜单没有多大意义。滑动应该提供一种在页面之间导航的方式,而不是一种全局导航的方式。这可能就是他们决定在 G+ 应用中采用与在 YouTube 应用中不同的方式的原因。另请注意,请查看 Google Play 应用程序以获取另一个版本的“拉出菜单”(当您位于最左侧的页面时,向左滑动并拉出,将出现“半页”菜单)。
You're right in that this isn't very consistent behavior, but it doesn't seem like there is a 100% consensus within the Android team on how this behavior should be implemented yet. I wouldn't be surprised if in the future the apps are updated so that the navigation in both apps are identical (they seemed very keen on making navigation consistent across all Google-made apps in the talk).
您是对的,因为这不是非常一致的行为,但 Android 团队内部似乎尚未就如何实施此行为达成 100% 的共识。如果将来更新应用程序以便两个应用程序中的导航相同,我不会感到惊讶(他们似乎非常热衷于在谈话中使所有 Google 制造的应用程序的导航保持一致)。
回答by Jared Burrows
Just recently I forked a current Github project called "RibbonMenu" and edited it to fit my needs:
就在最近,我分叉了一个名为“RibbonMenu”的当前 Github 项目并对其进行了编辑以满足我的需求:
https://github.com/jaredsburrows/RibbonMenu
https://github.com/jaredsburrows/RibbonMenu
What's the Purpose
目的是什么
- Ease of Access: Allow easy access to a menu that slides in and out
- Ease of Implementation: Update the same screen using minimal amount of code
- Independency: Does not require support libraries such as ActionBarSherlock
- Customization: Easy to change colors and menus
- 易于访问:允许轻松访问滑入和滑出的菜单
- 易于实施:使用最少的代码更新同一屏幕
- 独立性:不需要 ActionBarSherlock 等支持库
- 自定义:易于更改颜色和菜单
What's New
什么是新的
- Changed the sliding animation to match Facebook and Google+ apps
- Added standard ActionBar (you can chose to use ActionBarSherlock)
- Used menuitem to open the Menu
- Added ability to update ListView on main Activity
- Added 2 ListViews to the Menu, similiar to Facebook and Google+ apps
- Added a AutoCompleteTextView and a Button as well to show examples of implemenation
- Added method to allow users to hit the 'back button' to hide the menu when it is open
- Allows users to interact with background(main ListView) and the menu at the same time unlike the Facebook and Google+ apps!
- 更改了滑动动画以匹配 Facebook 和 Google+ 应用程序
- 添加标准ActionBar(您可以选择使用ActionBarSherlock)
- 使用 menuitem 打开菜单
- 添加了在主 Activity 上更新 ListView 的功能
- 向菜单添加了 2 个列表视图,类似于 Facebook 和 Google+ 应用程序
- 还添加了 AutoCompleteTextView 和 Button 以显示实施示例
- 添加了允许用户在打开菜单时点击“后退按钮”隐藏菜单的方法
- 与 Facebook 和 Google+ 应用程序不同,允许用户同时与背景(主 ListView)和菜单交互!
ActionBar with Menu out
带菜单的 ActionBar
ActionBar with Menu out and search selected
选择了菜单和搜索的 ActionBar
回答by naXa
There is a great implementation of NavigationDrawer
that follows the Google Material Design Guidelines (and compatible down to API 10) - The MaterialDrawer library (link to GitHub). As of time of writing, May 2017, it's actively supported.
有一个很好的实现NavigationDrawer
遵循 Google Material Design Guidelines(并兼容 API 10) - MaterialDrawer 库(链接到 GitHub)。截至撰写本文时,2017 年 5 月,它得到了积极支持。
It's available in Maven Central repo. Gradle dependency setup:
它在Maven Central repo 中可用。Gradle 依赖设置:
compile 'com.mikepenz:materialdrawer:5.9.1'
Maven dependency setup:
Maven 依赖设置:
<dependency>
????<groupId>com.mikepenz</groupId>
????<artifactId>materialdrawer</artifactId>
????<version>5.9.1</version>
</dependency>
回答by Sotti
I know this is an old question but the most up to date answer is to use the Android Support Design librarythat will make your life easy.
我知道这是一个老问题,但最新的答案是使用Android 支持设计库,这将使您的生活更轻松。
回答by Nicolas Jafelle
Personally I like the navigationDrawer
in Google Drive official app. It just works and works great. I agree that the navigation drawer shouldn't move the action bar because is the key point to open and close the navigation drawer.
我个人喜欢navigationDrawer
Google Drive 官方应用程序中的。它很好用,而且效果很好。我同意导航抽屉不应该移动操作栏,因为这是打开和关闭导航抽屉的关键。
If you are still trying to get that behavior I recently create a project Called SherlockNavigationDrawer
and as you may expect is the implementation of the Navigation Drawer with ActionBarSherlock
and works for pre Honeycomb devices. Check it:
如果您仍在尝试获得这种行为,我最近创建了一个名为 Called 的项目SherlockNavigationDrawer
,正如您所期望的那样,导航抽屉的实现ActionBarSherlock
适用于蜂窝设备之前的设备。核实: