问题描述
我想使用滑动菜单在我的应用程序。在我的索尼Xperia的IT工作得很好,但是当我尝试推出在HTC Desire HD的应用程序,菜单打开完美的用手势,但是其他触摸事件被封锁,顶视图( ViewPager
,滑动菜单后面)不会滚动。
是否有人知道如何解决这一问题?
也许它会给出一个答案有帮助(这是我如何使用菜单):
私人无效initSlidingMenu()
{
mSlidingMenu =新SlidingMenu(getApplicationContext());
mSlidingMenu.setMode(SlidingMenu.LEFT);
mSlidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
mSlidingMenu.setShadowWidthRes(R.dimen.default_shadow_width);
mSlidingMenu.setShadowDrawable(R.drawable.defaultshadow);
mSlidingMenu.setBehindOffsetRes(R.dimen.default_behind_offset);
mSlidingMenu.setFadeDegree(0.35f);
mSlidingMenu.setMenu(第一页);
mSlidingMenu.attachToActivity(这一点,SlidingMenu.SLIDING_CONTENT);
}
在 onPageSelected()
,我禁用菜单或启用它,所以菜单仅出现在左页:
@覆盖公共无效onPageSelected(INT为arg0)
{
ActivityCompat.invalidateOptionsMenu(本);
如果(将arg0 == Utils.DEFAULT_PAGE)
mSlidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
其他
mSlidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_NONE);
}
我有同样的问题与滑动菜单工作正常在我的三星Galaxy S2运行ICS却没有关于我的HTC Desire运行姜饼。
我用同样的方法为你实现滑动菜单,但我发现,另一种实现方式解决了这个问题。
不用手动安装菜单到你的活动 mSlidingMenu.attachToActivity(这一点,SlidingMenu.SLIDING_CONTENT);
我选择了从SlidingMenu库中的滑动活动之一致以活动。就我而言,我的活动被延长 FragmentActivity
在第一,但我通过 SlidingFragmentActivity
那你应该设置的onCreate
法里面的behindView或您的活动会崩溃。
setBehindContentView(R.layout.slidingmenu); //你的菜单的布局替换
这应该解决这个问题。
下面是我的活动的样本code:
公共类MainActivity扩展SlidingFragmentActivity {
SlidingMenu菜单;
@覆盖
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
//为活动主视图布局
的setContentView(R.layout.activity_listing);
//设置背后查看:必需(与你的菜单的布局替换)
setBehindContentView(R.layout.slidingmenu);
菜单= getSlidingMenu();
//现在你可以定制你的滑动菜单,如果你想
menu.setMode(SlidingMenu.LEFT);
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
menu.setShadowWidthRes(R.dimen.shadow_width);
menu.setShadowDrawable(R.drawable.slidingmenu_shadow);
menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
menu.setFadeDegree(0.35f);
您会注意到,这个解决方案,你不必叫
mSlidingMenu.setMenu(第一页);
mSlidingMenu.attachToActivity(这一点,SlidingMenu.SLIDING_CONTENT);
我还没有分析SlidingMenu库的所有源$ C $ C,但也许是电流 attachToActivity
方法是越野车在某些情况下和这些错误不会出现如果我们使用库提供的专项活动。
编辑:确定为那些谁正在使用的SlidingMenu图书馆和ActionBarSherlock(ABS)。首先,你必须确保ABS是在SlidingMenu LIB引用。这样一来,你就可以由ABS那些延长由SlidingMenu提供的活动类。
例如,如果我想使用FragmentActivity既ABS和滑动菜单:你在滑动菜单库更改
类SlidingFragmentActivity扩展FragmentActivity实现SlidingActivityBase
按
类SlidingFragmentActivity扩展SherlockFragmentActivity实现SlidingActivityBase
然后在你的应用程序,使用 SlidingFragmentActivity
正常。
下面是我的应用程序的code,它就像一个我张贴,但有ABS的支持:
公共类MainActivity扩展SlidingFragmentActivity {
动作条mActionBar;
SlidingMenu菜单;
@覆盖
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.activity_listing); //以上观点的布局
/ *
* ABS初始化
* /
mActionBar = getSupportActionBar();
mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
mActionBar.setDisplayHomeAsUpEnabled(真正的);
/ *
*滑动菜单初始化
* /
菜单= getSlidingMenu();
menu.setMode(SlidingMenu.LEFT);
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
menu.setShadowWidthRes(R.dimen.shadow_width);
menu.setShadowDrawable(R.drawable.slidingmenu_shadow);
menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
menu.setFadeDegree(0.35f);
/ *此行初始化滑动菜单的工作方式
如果将布尔为true,动作条会滑动随着内容。
如果设置为false,只有内容和滑动的动作条不会动* /
setSlidingActionBarEnabled(真正的);
//设置背后查看
setBehindContentView(R.layout.slidingmenu); //功能表视图
I'm trying to use Sliding Menu in my application. On my Sony Xperia S it works very nice, but when I try to launch app on HTC Desire HD, menu opens perfect by gesture, but other touch events are blocked and top view (ViewPager
, sliding menu is behind it) is not scrolling.
Does anybody know how to fix this?
May be it will be helpful to give an answer (This is how I'm using menu):
private void initSlidingMenu()
{
mSlidingMenu = new SlidingMenu(getApplicationContext());
mSlidingMenu.setMode(SlidingMenu.LEFT);
mSlidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
mSlidingMenu.setShadowWidthRes(R.dimen.default_shadow_width);
mSlidingMenu.setShadowDrawable(R.drawable.defaultshadow);
mSlidingMenu.setBehindOffsetRes(R.dimen.default_behind_offset);
mSlidingMenu.setFadeDegree(0.35f);
mSlidingMenu.setMenu(firstPage);
mSlidingMenu.attachToActivity(this,SlidingMenu.SLIDING_CONTENT);
}
In onPageSelected()
, I disable menu or enable it, so menu appears only at left page:
@Override public void onPageSelected(int arg0)
{
ActivityCompat.invalidateOptionsMenu(this);
if (arg0 == Utils.DEFAULT_PAGE)
mSlidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
else
mSlidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_NONE);
}
I just had the same problem with the Sliding menu working fine on my Samsung Galaxy S2 running ICS but not on my HTC Desire running Gingerbread.
I used the same method as you to implement the sliding menu but I found that another implementation solved the problem.
Instead of manually attaching the menu to your activity :
mSlidingMenu.attachToActivity(this,SlidingMenu.SLIDING_CONTENT);
I chose to extend my Activity by one of the Sliding activities from the SlidingMenu library. In my case, my Activity was extending FragmentActivity
at first but I replaced it by SlidingFragmentActivity
Then you should set the behindView inside the onCreate
method or your activity will crash.
setBehindContentView(R.layout.slidingmenu); //Replace with the layout of your menu
It should fix the problem.
Here is a sample code of my Activity :
public class MainActivity extends SlidingFragmentActivity {
SlidingMenu menu;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Main view layout for the activity
setContentView(R.layout.activity_listing);
// set the Behind View : REQUIRED (replace with your menu's layout)
setBehindContentView(R.layout.slidingmenu);
menu = getSlidingMenu();
//Now you can customize your sliding menu if you want
menu.setMode(SlidingMenu.LEFT);
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
menu.setShadowWidthRes(R.dimen.shadow_width);
menu.setShadowDrawable(R.drawable.slidingmenu_shadow);
menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
menu.setFadeDegree(0.35f);
You will note that with this solution you don't have to call
mSlidingMenu.setMenu(firstPage);
mSlidingMenu.attachToActivity(this,SlidingMenu.SLIDING_CONTENT);
I haven't analyzed all the source code of the SlidingMenu library but maybe the current attachToActivity
method is buggy in some cases and those bugs don't appear if we use the special activities provided by the library.
EDIT : Ok for those who are working with the SlidingMenu library AND ActionBarSherlock (ABS).First you have to make sure that ABS is referenced in the SlidingMenu lib. That way, you'll be able to extend the activities classes provided by SlidingMenu by the ABS ones.
Example if I want to use an FragmentActivity with both ABS and Sliding menu :you have to change in the sliding menu library
class SlidingFragmentActivity extends FragmentActivity implements SlidingActivityBase
by
class SlidingFragmentActivity extends SherlockFragmentActivity implements SlidingActivityBase
And then in you application, use the SlidingFragmentActivity
normally.
Here is the code of my app, it is like the one I posted but with ABS support :
public class MainActivity extends SlidingFragmentActivity {
ActionBar mActionBar;
SlidingMenu menu;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_listing); //Layout of the above view
/*
* ABS initialization
*/
mActionBar = getSupportActionBar();
mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
mActionBar.setDisplayHomeAsUpEnabled(true);
/*
* Sliding menu initialization
*/
menu = getSlidingMenu();
menu.setMode(SlidingMenu.LEFT);
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
menu.setShadowWidthRes(R.dimen.shadow_width);
menu.setShadowDrawable(R.drawable.slidingmenu_shadow);
menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
menu.setFadeDegree(0.35f);
/* This line initializes the way the sliding menu is working
if you set the boolean to true, the ActionBar will slide along with the content.
if you set to false, only the content will slide and the ActionBar will not move */
setSlidingActionBarEnabled(true);
// set the Behind View
setBehindContentView(R.layout.slidingmenu); //Menu view
这篇关于滑动菜单锁定在顶视图触摸事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!