Search code examples
androidnavigation-drawerdrawerlayout

Set drawer view width to wrap content in DrawerLayout


I have a DrawerLayout with a FrameLayout for the content and a ListView for the drawer.

I want the opened drawer to be just as wide as needed to fit all the items widths.

I tried setting wrap_content in the ListView and in the row layout but the drawer always fills about 80% of the screen. It only changes when I set the ListView width to a fixed dp value.

How should I be doing it?


Solution

  • Navigation Drawer width should be screen width minus the height of the action bar(toolbar, etc) means between 240dp to 360dp. I believe NavigationView class automatically sets true width if set to wrap content. so if u want to wrap list view's content use Framelayout (old solution) or write a your own NavigationView class.