为什么DrawerLayout有时毛刺在打开? [英] Why does DrawerLayout sometimes glitch upon opening?

查看:119
本文介绍了为什么DrawerLayout有时毛刺在打开?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照教程导航抽屉,一切的工作方式类似,除了一个魅力一个小故障。我会尽力解释它尽可能多的,如果它仍然是不明确的,我会尝试上载该问题的视频。

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.

当试图打开抽屉,只有当打开,只有有时会发生,不总是问题发生。这时候,我开始打开它的毛刺,并冻结与大约4毫米开放的,始终不变的距离。然后,它会不会继续开放,也没有收回来,如果我将我的手指回来,当我放手,它关闭。

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.

请注意:

  • 我已经尝试过在多个设备上(的Nexus 7,Nexus的)和虚拟设备为好,问题仍然存在。
  • 发行使用谷歌提供的例子复制。 (YouTube链接)
  • psented与我的应用程序
  • 问题$ P $。 (YouTube链接)
  • 我设法在Gmail应用程序(我相信使用同样的实现)复制发行一次,但只有一次,但更加频繁与我的应用程序和示例应用程序。
  • 我注意到,故障发生在哪个抽屉打开,如果你只要按一下屏幕边缘,如后初期开放的冻结,从不拖动相同的距离。
  • 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.

任何指针将AP preciated。

Any pointers would be appreciated.

推荐答案

我研究 DrawerLayout 的code,找到了下一个问题: 当我们触摸屏幕的边缘,似乎在抽屉小(20 *密度像素)的部分(它使移动的抽屉更容易)。它不出现立刻,而是在一定的时间间隔(160毫秒)后。它是由 postDelayed 实现。

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 the drawer (it makes moving drawer easier). It doesn't appears immediatly, but after a certain interval (160 ms) of time. It is realized by postDelayed.

抽屉可以在几种状态: IDLE 拖动如果 SETTLING 。如果是在拖动如果状态,它不能与同一指针和边缘恢复到这种状态了(因为有一个条件: mEdgeDragsInProgress [pointerId ]安培;边缘)==边缘不允许拖动已经拖动已经)的边缘。

The drawer can be in several states: IDLE, DRAGGING and SETTLING. If it was in the DRAGGING 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).

因此​​,在某些情况下,抽屉已经转移到国家拖动如果已延迟时的Runnable 正在执行。这种延迟操作打开抽屉 20 *密度像素,并更改抽屉的状态。因此,抽屉无法再移动(因为它无法恢复的状态拖动如果)。

So in some cases the drawer have moved to the state DRAGGING already when delayed Runnable is executing. This delayed action opens drawer for 20*density px and change state of drawer. So drawer cannot be moved anymore (because it cannot return to the state DRAGGING).

有一个code取消延迟行动(这将打开抽屉),但这code的方法 onInterceptTouchEvent ,这被称为一次(因为它返回)。我想,这code应该在方法的onTouchEvent

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 returns false). I think this code should be in the method onTouchEvent.

不幸的是我没有找到任何办法来取消延迟事件(因为它有私人修改,我无法得到它)。因此,只有一个办法,我发现:复制 DrawerLayout 源$ C ​​$ C到我的项目,使这个小小的变化:复制

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 of DrawerLayout to my project and make this small change: copy

case MotionEvent.ACTION_MOVE: {
            // If we cross the touch slop, don't perform the delayed peek for an edge touch.
            if (mLeftDragger.checkTouchSlop(ViewDragHelper.DIRECTION_ALL)) {
                mLeftCallback.removeCallbacks();
                mRightCallback.removeCallbacks();
            }
            break;
        }

从方法 onInterceptTouchEvent 的方法的onTouchEvent

这篇关于为什么DrawerLayout有时毛刺在打开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆