-1

The DrawerLayout take noticeable time to close here is my code:

            @Override
            public void onDrawerOpened(View drawerView) {

                   if (items.size() == 0)
                      view.setVisibility(View.GONE);
                   else view.setVisibility(View.VISIBLE);}

                super.onDrawerOpened(drawerView);
                invalidateOptionsMenu();

            }

is there a solution for that?

Radwa
  • 325
  • 4
  • 21

2 Answers2

1

Your problem is that the onDrawerOpened() method doesn't fire until the drawer is completely open. The perceived delay is due to the View being visible during the opening.

One solution would be to disable dragging the drawer, and only allow the toggle to open and close it. You could then do your size check before opening it programmatically. This, though, would require locking the drawer to the appropriate state in each of the onDrawerOpened() and onDrawerClosed() methods, and, of course, you'd lose that standard mode of interaction.

The preferred option is probably to do the check and visibility setting as soon as possible as the drawer is starting to open. We can do this in the onDrawerSlide() method instead, keeping a boolean flag to determine if the drawer is sliding after having been closed. For example:

actionBarDrawerToggle = new ActionBarDrawerToggle(...) {
    private boolean opened;

    @Override
    public void onDrawerSlide(View drawerView, float slideOffset) {
        super.onDrawerSlide(drawerView, slideOffset);

        if (slideOffset == 0) {
            opened = false;
        }
        else {
            if (!opened) {
                opened = true;
                if (items.size() == 0) {
                    view.setVisibility(View.GONE);
                }
                else {
                    view.setVisibility(View.VISIBLE);
                }
            }   
        }
    }

    ...
}
Mike M.
  • 38,532
  • 8
  • 99
  • 95
0

have you include

actionBarDrawerToggle.syncState()

What does syncState() exactly do?

Well, ActionBarDrawerToggle.syncState() will synchronize the changed icon's state, which deponds on actions of DrawerLayout. If you ever tried to remove the syncState(), you will realize that the icon of arrow won't rotate any more.

Harmantj
  • 182
  • 2
  • 11