android - Material Design: Nav Drawer Width -
android - Material Design: Nav Drawer Width -
according the material design specs nav drawer's width on mobile devices must
side nav width = screen width - app bar height
how implement on android?
i have 2 partial solutions. first hacky way: in containing activity set code:
if (build.version.sdk_int > build.version_codes.honeycomb_mr1) { final display display = getwindowmanager().getdefaultdisplay(); final point size = new point(); display.getsize(size); final viewgroup.layoutparams params = mdrawerfragment.getview().getlayoutparams(); params.width = size.x - getresources().getdimensionpixelsize( r.dimen.abc_action_bar_default_height_material ); mfragmentuserlist.getview().setlayoutparams(params); }this, however, causes sec layout cycle , doesn't work in gingerbread: not optimal.
the sec solution involves adding space between fragment , drawerlayout. however, displaces shadow , spot user can press homecoming main app. crashes when "hamburguer" icon pressed. not optimal either.
is there improve solution, preferably 1 involves styles , xml?
with android design back upwards library simple implement navigation drawer including right sizing. utilize navigationview , either utilize ability create drawer out of menu resource (example here) or can wrap around view currenty utilize showing drawer list (e.g. listview, recyclerview). navigationview take care of drawer sizing you.
here's illustration how utilize navigationview wrapped around listview:
<?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.drawerlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/navdrawer_layout" android:fitssystemwindows="true"> <!-- layout content shown --> <relativelayout android:layout_width="match_parent" android:layout_height="match_parent"> <include android:id="@+id/toolbar" layout="@layout/toolbar" /> <framelayout android:id="@+id/content_frame" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@id/toolbar" /> <!-- toolbar shadow pre-lollipop --> <view style="@style/toolbardropshadow" android:layout_width="match_parent" android:layout_height="3dp" android:layout_below="@id/toolbar" /> </relativelayout> <android.support.design.widget.navigationview android:id="@+id/navigation_view" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="start"> <listview android:id="@+id/navdrawer_list" android:layout_width="match_parent" android:layout_height="match_parent" android:choicemode="singlechoice" android:dividerheight="0dp" android:divider="@null"/> </android.support.design.widget.navigationview> </android.support.v4.widget.drawerlayout>
this way can utilize navigationviews sizing , still utilize own drawer list. though much easier create drawer list out of menu resource (example here) can't utilize custom views list items.
android appcompat material-design
Comments
Post a Comment