android - Why i can't lock DrawerLayout with layout gravity -
i use drawerlayout , want change gravity of listview in drawerlayout. after change gravity of listview android:layout_gravity="start|bottom"
from android:layout_gravity="start"
, drawerlayout can't lock
mdrawer.setdrawerlockmode(drawerlayout.lock_mode_locked_closed);
setdrawerlockmode() work with;
<android.support.v4.widget.drawerlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" > <relativelayout android:layout_width="match_parent" android:layout_height="match_parent" > </relativelayout> <listview android:id="@+id/drawer_list" android:layout_width="320dp" android:layout_height="match_parent" android:layout_gravity="start" android:background="#f3f3f4" android:choicemode="singlechoice" > </listview>
but doesn't lock with;
<android.support.v4.widget.drawerlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" > <relativelayout android:layout_width="match_parent" android:layout_height="match_parent" > </relativelayout> <listview android:id="@+id/drawer_list" android:layout_width="320dp" android:layout_height="match_parent" android:layout_gravity="start|bottom" android:background="#f3f3f4" android:choicemode="singlechoice" > </listview>
`
any clues of why can't use lock mode other gravities?
thanks!
based on documentation, only available gravities can used gravity.left
, gravity.right
or gravitycompat.start
, gravitycompat.end
.
(emphasis mine):
drawer positioning , layout controlled using android:layout_gravity attribute on child views corresponding side of view want drawer emerge from: left or right. (or start/end on platform versions support layout direction.)
looking @ source code
public void setdrawerlockmode(int lockmode, int edgegravity) { final int absgrav = gravitycompat.getabsolutegravity(edgegravity, viewcompat.getlayoutdirection(this)); if (absgrav == gravity.left) { mlockmodeleft = lockmode; } else if (absgrav == gravity.right) { mlockmoderight = lockmode; } if (lockmode != lock_mode_unlocked) { // cancel interaction in progress final viewdraghelper helper = absgrav == gravity.left ? mleftdragger : mrightdragger; helper.cancel(); } switch (lockmode) { case lock_mode_locked_open: final view toopen = finddrawerwithgravity(absgrav); if (toopen != null) { opendrawer(toopen); } break; case lock_mode_locked_closed: final view toclose = finddrawerwithgravity(absgrav); if (toclose != null) { closedrawer(toclose); } break; // default: nothing } }
the method checks if gravity left
or right
(but uses gravitycompat
method, start
, end
should appropriately translated).
this mean setting gravity of "start|bottom"
, you're introducing invalid gravity, causes setdrawerlockmode()
nothing.
Comments
Post a Comment