Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DrawerLayout getting stuck on swipe

I am playing around with DrawerLayout and I am encountering an issue. Basically sometimes when i swipe from the edge of the screen the DrawerLayout will get stuck until i lift my finger off the screen (See screenshot below)

I am not sure what is up, I followed the code sample from the google sdk exactly. Any ideas?

Screenshot bug

And here is the only thing i have in my FragmentActivity:

@Override     protected void onCreate(Bundle savedInstanceState)     {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_main);         final String[] names =                 getResources().getStringArray(R.array.nav_names);         ArrayAdapter<String> adapter =                 new ArrayAdapter<String>(                         getActionBar().getThemedContext(),                         android.R.layout.simple_list_item_1, names);          final DrawerLayout drawer =                 (DrawerLayout)findViewById(R.id.drawer_layout);         final ListView navList =                 (ListView) findViewById(R.id.drawer);         navList.setAdapter(adapter);         navList.setOnItemClickListener(new AdapterView.OnItemClickListener()         {              @Override             public void onItemClick(AdapterView<?> parent,                                     View view, final int pos, long id)             {                 drawer.setDrawerListener(                         new DrawerLayout.SimpleDrawerListener()                         {                             @Override                             public void onDrawerClosed(View drawerView)                             {                                 super.onDrawerClosed(drawerView);                              }                         });                 drawer.closeDrawer(navList);             }         });      } 

EDIT:I'm adding a bounty on this, as this is a very old issue that exists even today with the latest Android-X (sample available here). Here's how it looks:

enter image description here

I've reported about it to Google (here and later again here), but it didn't help.

I've tried all existing solutions here on this thread, and none worked. If anyone has a good workaround for this (while still using DrawerLayout or extending it, or something similar), please put a working solution.

like image 854
thunderousNinja Avatar asked Aug 03 '13 06:08

thunderousNinja


People also ask

How do you use DrawerLayout?

To use a DrawerLayout, position your primary content view as the first child with width and height of match_parent and no layout_gravity> . Add drawers as child views after the main content view and set the layout_gravity appropriately. Drawers commonly use match_parent for height with a fixed width.

How do you change the DrawerLayout icon on the right side of the device screen?

Edit. According to Creating a Navigation Drawer, The drawer view (the ListView) must specify its horizontal gravity with the android:layout_gravity attribute. To support right-to-left (RTL) languages, specify the value with "start" instead of "left" (so the drawer appears on the right when the layout is RTL).

What is DrawerLayout?

Drawer Layout In Android: In Android, DrawerLayout acts as top level container for window content that allows for interactive “drawer” views to be pulled out from one or both vertical edges of the window.


Video Answer


1 Answers

Note that you can get around this 20dp peek feature by setting the clickable attribute to true on the FrameLayout within the DrawerLayout.

android:clickable="true"

for instance : http://developer.android.com/training/implementing-navigation/nav-drawer.html

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/drawer_layout"     android:layout_width="match_parent"     android:layout_height="match_parent">     <!-- The main content view -->     <FrameLayout         android:id="@+id/content_frame"         android:layout_width="match_parent"         android:layout_height="match_parent"         android:clickable="true" />     <!-- The navigation drawer -->     <ListView         android:id="@+id/left_drawer"         android:layout_width="240dp"         android:layout_height="match_parent"         android:layout_gravity="start"         android:background="#111"         android:choiceMode="singleChoice"         android:divider="@android:color/darker_gray"         android:dividerHeight="1dp" /> </android.support.v4.widget.DrawerLayout> 
like image 72
Akos Cz Avatar answered Sep 19 '22 14:09

Akos Cz