I have followed the tutorial Navigation Drawer and everything works like a charm except for a small glitch. I'll try to explain it as much as possible, and if it still isn't clear, I'll try to upload a video of the problem.
Problem happens when trying to open the drawer and only when opening, and only happens sometimes, not always. That is when I start to open it it glitches and freezes with about 4 millimeters open, and always the same distance. It then would not continue opening nor close back if I move my finger back, when I let go, it closes.
Please note:
- I have tried it on multiple devices (Nexus 7, Nexus) and virtual devices as well, problem persists.
- Issue replicated using the example provided by Google. (Youtube Link)
- Issue presented with my app. (Youtube Link)
- I managed to replicated the issue once but only once in Gmail app (which I believe uses the same implementation), however much more frequent with my app and the sample app.
- I noticed that the glitch happens at the same distance of which the drawer opens if you just click the edge of the screen, as in it freezes after initial open and never drags.
Any pointers would be appreciated.
There is no error in drawerlayout file. Just add a ScrollView as the parent or root view to the content.xml(setcontentview file) file and tools:context=".MainActivity"
I researched the code of
DrawerLayout
and found the next issue: When we touch the edge of screen there appears small (20*density px) part of thedrawer
(it makes moving drawer easier). It doesn't appears immediatly, but after a certain interval (160 ms) of time. It is realized bypostDelayed
.The
drawer
can be in several states:IDLE
,DRAGGING
andSETTLING
. If it was in theDRAGGING
state, it cannot return to this state anymore with the same pointer and edge (because there is a condition:mEdgeDragsInProgress[pointerId] & edge) == edge
which doesn't allow to drag the edge which have been dragging already).So in some cases the drawer have moved to the state
DRAGGING
already when delayedRunnable
is executing. This delayed action opensdrawer
for 20*density px and change state ofdrawer
. Sodrawer
cannot be moved anymore (because it cannot return to the stateDRAGGING
).There is a code for cancelling delayed action (which opens drawer), but this code in the method
onInterceptTouchEvent
, which is called only once (because it returnsfalse
). I think this code should be in the methodonTouchEvent
.Unfortunatly I didn't find any way to cancel delayed event (because it has
private
modifier and I can't get it). So only one way I found: copy the source code ofDrawerLayout
to my project and make this small change: copyfrom the method
onInterceptTouchEvent
to the methodonTouchEvent
.