新的Facebook应用程序和它的导航太酷了。我只是想看看如何在我的应用程序中模仿它。

有人知道怎么实现吗?

点击左上角按钮,页面滑动,显示如下画面:

YouTube视频


当前回答

随着android支持包修订版13(2013年5月),有了用于创建导航抽屉的DrawerLayout,可以从窗口边缘拉入。导航抽屉现在是一种设计模式。

V4支持库

导航抽屉设计模式

其他回答

做了一个现有的实现,并把它变成一个库项目加上示例应用程序。还添加了XML解析以及自动检测可能出现的动作栏,所以它与本机以及支持动作栏,如ActionBarSherlock。

这个也会滑动操作栏!

整个事情是一个图书馆项目与一个示例应用程序,并在一个滑动菜单为Android像谷歌和facebook应用程序的描述。感谢scirocco最初的想法和代码!

我在过去的几天里一直在玩这个,我已经提出了一个解决方案,这是相当直接的,在pre-Honeycomb。我的解决方案是动画我想要滑动的视图(FrameLayout为我),并监听动画的结束(在这一点上抵消视图的左/右位置)。我在这里粘贴了我的解决方案:如何动画一个视图的翻译

我在这里做一些大胆的猜测……

我假设它们有一个表示不可见的菜单的布局。当点击菜单按钮时,它们会在顶部移动布局/视图,并简单地启用菜单布局的可见性。我没有想过这会在视图中引起任何类型的z索引问题,或者他们如何控制它。

对于信息,因为兼容性库开始1.6和这个facebook应用程序也运行在设备与Android 1.5,它不能用碎片。

The way you could do it, is : Create a "base" activity BaseMenuActivity where you put all the logic for the onItemClickListener for your menu list and defines the 2 animation ("open" and "close"). At the end/beginning of the animations, you show/hide the layout of the BaseMenuActivity (lets call it menu_layout). The layout for this activity is simple, its only a list with items + a transparent part at the right of your list. This part will be clickable and its width will be the same width as your "move button". With that, you'll be able to click on this layout to start the animation to let the content_layout slide to the left and take the whole screen. For each option (i.e. item of the menu list), you create a "ContentActivity" which extends the BaseMenuActivity. Then when you click on an item of the list, you start your ItemSelectedContentActivity with the menu visible (which you'll close as soon as your activity starts). The layouts for each ContentActivity are FrameLayout and includes the and . You just need to move the content_layout and make the menu_layout visible when you want.

这是一种方法,我希望我讲得够清楚了。

经过几个小时的搜索,我发现保罗·格里姆的解决方案可能是最好的。但是它有太多的功能。因此,对于初学者来说,学习汉语可能很难。所以我想提供我的实现,它来自Paul的想法,但它更简单,应该更容易阅读。

通过使用java代码实现侧菜单栏,没有XML