简体   繁体   English

如何在ViewPager中使用SlidingMenu?

[英]How to use SlidingMenu with ViewPager?

I have ViewPager with content in MainActivity and I want to add SlidingMenu. 我的ViewPager包含MainActivity中的内容,我想添加SlidingMenu。 I need that the SlidingMenu open only on the first page of ViewPager. 我需要SlidingMenu只在ViewPager的第一页打开。 I've found this example , but in this implementation it doesn't working well: it hard to open menu (SlidingMenu only react on narrow left side of screen) and working on every page (not only first). 我已经找到了这个例子 ,但是在这个实现中它不能很好地工作:很难打开菜单(SlidingMenu只在屏幕的左侧做出反应)并且在每个页面上工作(不仅仅是第一个)。 How to implement it properly? 如何正确实施?

Regardless of your answer to my comment/question regarding your implementation of an ActionBar, you could modify the SlidingMenu source so that the margin for TOUCHMODE_MARGIN is larger. 无论您对我的ActionBar实现的评论/问题的答案如何,您都可以修改SlidingMenu源,以便TOUCHMODE_MARGIN的边距更大。 Open up CustomViewAbove.java in the com.slidingmenu.lib package and set the MARGIN_THRESHOLD int to something larger than 20. I used 80. 打开CustomViewAbove.javacom.slidingmenu.lib包和设置MARGIN_THRESHOLD INT到一些比20.我用80大。

OPINION: I think jfeinstein should make that margin larger anyway or, at the very least, configurable. 意见:我认为jfeinstein无论如何应该使这个边际更大,或者至少是可配置的。

If you don't want to do that, and you are implementing an ActionBar, you could simply use the ActionBar Home button and simply open the SlidingMenu that way. 如果你不想这样做,并且你正在实现一个ActionBar,你可以简单地使用ActionBar Home按钮,然后只需打开SlidingMenu。 See https://stackoverflow.com/a/11409318/1165673 for reference. 请参阅https://stackoverflow.com/a/11409318/1165673以供参考。

To address the issue of only being available on the first page of the ViewPager , take a look at the setSlidingEnabled(bool b) function in SlidingMenu.java . 为了解决仅是可用的第一页上的问题ViewPager ,看看在setSlidingEnabled(bool b)在功能上SlidingMenu.java You know which page you are on, so set sliding enabled based on your location. 您知道自己所在的页面,因此请根据您的位置设置启用滑动功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM