SlidingMenu
SlidingMenu copied to clipboard
All touch events are consumed by CustomViewAbove
If I use the SlidingMenu together with ActionBarSherlock (maybe unrelated) and with this settings:
SlidingMenu sm = getSlidingMenu();
sm.setShadowWidthRes(R.dimen.shadow_width);
sm.setShadowDrawable(R.drawable.shadow);
sm.setBehindOffsetRes(R.dimen.slidingmenu_offset);
sm.setFadeDegree(0.35f);
sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
sm.setTouchModeBehind(SlidingMenu.TOUCHMODE_FULLSCREEN);
I cannot use the view behind which has the effect that I cannot react on onListItemClick(...)
in my ListFragment
after days of research I found out that there is a bug in the CustomViewAbove
.
My primary fix is to change a break
in onInterceptTouchEvent()
to return mQuickReturn;
. So the ACTION_DOWN
event code will look like this:
case MotionEvent.ACTION_DOWN:
int index = MotionEventCompat.getActionIndex(ev);
mActivePointerId = MotionEventCompat.getPointerId(ev, index);
if (mActivePointerId == INVALID_POINTER)
break;
mLastMotionX = mInitialMotionX = MotionEventCompat.getX(ev, index);
mLastMotionY = MotionEventCompat.getY(ev, index);
if (thisTouchAllowed(ev)) {
mIsBeingDragged = false;
mIsUnableToDrag = false;
if (isMenuOpen() && mViewBehind.menuTouchInQuickReturn(mContent, mCurItem, ev.getX() + mScrollX)) {
mQuickReturn = true;
}
} else {
mIsUnableToDrag = true;
}
return mQuickReturn;
Update: And also the onTouchEvent
you need to change the case MotionEvent.ACTION_DOWN
. There you need to replace the break
with another return mQuickReturn
. The case will look like that:
case MotionEvent.ACTION_DOWN:
/*
* If being flinged and user touches, stop the fling. isFinished
* will be false if being flinged.
*/
completeScroll();
// Remember where the motion event started
int index = MotionEventCompat.getActionIndex(ev);
mActivePointerId = MotionEventCompat.getPointerId(ev, index);
mLastMotionX = mInitialMotionX = ev.getX();
return mQuickReturn;
</update>
I also removed the setInternalPageChangeListener
in initCustomViewAbove()
. (The reason comes later.)
In the CustomViewBehind
I changed the code of the functions onInterceptTouchEvent
and onTouchEvent
to use the code from the CustomViewAbove
:
@Override
public boolean onInterceptTouchEvent(MotionEvent e) {
return !mChildrenEnabled;
}
@Override
public boolean onTouchEvent(MotionEvent e) {
return !mChildrenEnabled;
}
Now the part with the ChildrenEnabled is not anymore used and the function setChildrenEnabled
and the member mChildrenEnabled
can be removed.
Hopfully this will help others. By the way I would like to make a PushRequest but I don't know how to make that.
I have exactly the same issue but following your post I still unable to resolve it. Am I right that when you say "In the CustomViewBehind I changed the code of the functions onInterceptTouchEvent and onTouchEvent to use the code from the CustomViewAbove" you mean that your code becomes like this:
@Override public boolean onInterceptTouchEvent(MotionEvent e) { return mViewAbove.onInterceptTouchEvent(e); }
@Override public boolean onTouchEvent(MotionEvent e) { return mViewAbove.onTouchEvent(e); }
Yes that replaces the actual code.
Hmmm, then I have no idea why your changes are not working in my case.
-------- Исходное сообщение --------
От: rekire [email protected]
Дата:
Кому: jfeinstein10/SlidingMenu [email protected]
Cc: techy777 [email protected]
Тема: Re: [SlidingMenu] All touch events are consumed by CustomViewAbove (#446)
Yes that replaces the actual code.
— Reply to this email directly or view it on GitHub.
Which is your target platform? I just reconized that this fix works on a API 17 device but not on a API 10 device. I'll try to fix that tomorrow.
Great thanks. My target is API 10
-------- Исходное сообщение --------
От: rekire [email protected]
Дата:
Кому: jfeinstein10/SlidingMenu [email protected]
Cc: techy777 [email protected]
Тема: Re: [SlidingMenu] All touch events are consumed by CustomViewAbove (#446)
Which is your target platform? I just reconized that this fix works on a API 17 device but not on a API 10 device. I'll try to fix that tomorrow.
— Reply to this email directly or view it on GitHub.
While removing all my debug messages I made a mistake I forgot to add another change: The onTouchEvent
must be changed. In the case MotionEvent.ACTION_DOWN
you need to replace the break
with another return mQuickReturn
. The case will look like that:
case MotionEvent.ACTION_DOWN:
/*
* If being flinged and user touches, stop the fling. isFinished
* will be false if being flinged.
*/
completeScroll();
// Remember where the motion event started
int index = MotionEventCompat.getActionIndex(ev);
mActivePointerId = MotionEventCompat.getPointerId(ev, index);
mLastMotionX = mInitialMotionX = ev.getX();
return mQuickReturn;
Great job! Thank you very much. Now it perfectly works!
I'd changed library as said by you, but problem is not solved. Still menu not sliding. This is my Sliding menu code SlidingMenu sm = getSlidingMenu(); DisplayMetrics metric = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metric); sm.setBehindOffset(metric.widthPixels/3); sm.setFadeDegree(0.35f); sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN); sm.setTouchModeBehind(SlidingMenu.TOUCHMODE_FULLSCREEN);
P.S. : now it is not possible to slide from the above view if there is no item in listview (it only slides from listview items)
it is not possible to slide from the above view
Just as ramannjindal said ,it is not possible to slide from the above view if there is no item in listview (it only slides from listview items).
Hi, rekire, I follow your changes, but found that the left can slide off, but can not slide off the right side. Please help me. Thank you very much!
Hi, rekire, I follow your changes, but found that the left can slide off, but can not slide off the right side. Please help me. Thank you very much!
There is no one way, please help
This issue has been resolved, then this I thank rekire, because before I did not view it leads to the right side of the slide can not add the View view after the OK Specific solutions, please refer to # 466 Thank you very much
Nice,thanks very much.
It is Great!! Thanks very much!
Great job!!
great job !
the solution doesn't work for the right slidingmenu.
thanks,but there is still some problems... I changed my code as you said,it really does work,the behind view can slide and the item can click, but the above view cannot slide,I am new to Android,I don't know how to fix it...
Sorry I do not use this project anymore. So I cannot support you.
only add rekire solution and android:clickable="true" to your above screen layout root element and above can slide and behind is clickable :)
@MicoDevelopers thank you very much!!!It works.
great job ! thanks!
I have a problem
If you stil here???
Well I am alive and I feel good. Happy new year by the way!
If you have a question about that library, that is a problem as I already wrote on 11 Aug 2015 "Sorry I do not use this project anymore. So I cannot support you.".
也是
发自我的小米手机在 dongerhuo [email protected],2016年1月6日 下午4:57写道:If you stil here???
—Reply to this email directly or view it on GitHub.
感谢楼主
thanks