DrawerLayout - Exception dispatching input event

后端 未结 5 1512
悲&欢浪女
悲&欢浪女 2020-12-14 23:14

I recently started using the DrawerLayout in a new project about a week ago and it\'s all working fine. Apart from the odd times when swiping it in and out with my finger it

5条回答
  •  無奈伤痛
    2020-12-14 23:42

    I think I've managed to fix this by creating my own copies of the files I needed from the support library source code and catching the null View in isContentView().

    The files I needed from the source were:

    • ActionBarDrawerToggle.java
    • ActionBarDrawerToggleHoneycomb.java
    • DrawerLayout.java

    I put them in their own package in my project and renamed DrawerLayout to FixedDrawerLayout. (So I can easily tell which copy of the DrawerLayout I'm using)

    I then changed isContentView() to:

    boolean isContentView(View child) {
        if(child == null){
            return false;
        }
        return ((LayoutParams) child.getLayoutParams()).gravity == Gravity.NO_GRAVITY;
    }
    

    After swapping all references to the DrawerLayout in my Activity to FixedDrawerLayout it seems to have fixed it.

    Not sure if there is anything that can happen by just returning false in isContentView(), but it doesn't crash anymore and it's still usable even when child is null.

提交回复
热议问题