1. 程式人生 > >解決側滑中ViewPager和SlidingMenu的滑動衝突

解決側滑中ViewPager和SlidingMenu的滑動衝突

當我們在使用開源框架SlidingMenu時,如果要是使用到ViewPager,就會出現滑動衝突。

解決方案:


}/** 解決ViewPager和側滑衝突 */
	public void changeSlidingMenuTOUCHMODE(int arg0) {


		switch (arg0) {
		case 0:
			if (getActivity() instanceof SlidingFragmentActivity) {
				SlidingFragmentActivity activity = (SlidingFragmentActivity) getActivity();
				activity.getSlidingMenu().setTouchModeAbove(
						SlidingMenu.TOUCHMODE_FULLSCREEN);
			}
			break;


		default:


			if (getActivity() instanceof SlidingFragmentActivity) {
				SlidingFragmentActivity activity = (SlidingFragmentActivity) getActivity();
				activity.getSlidingMenu().setTouchModeAbove(
						SlidingMenu.TOUCHMODE_MARGIN);
			}
			break;
		}
	}
然後在viewpager的setOnPageChangeListener事件監聽中的onPageSelected方法中呼叫changeSlidingMenuTOUCHMODE(page);

程式碼如下:

@Override
			public void onPageSelected(int page) {
				// TODO Auto-generated method stub
				changeSlidingMenuTOUCHMODE(page);
			}