I'd like to create a full width navigation drawer. Setting layout_width
to match_parent
on @+id/left_drawer
yields in width of about 80% of screen space. This seems to be the standard behavior. Do I have to override onMeasure()
of DrawerLayout
?
My current code:
<?xml version="1.0" encoding="utf-8"?>
<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">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black"
android:id="@+id/mainFragmentContainer">
</FrameLayout>
<include
android:id="@+id/left_drawer"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
layout="@layout/drawer"/>
</android.support.v4.widget.DrawerLayout>
Thanks.
A variant on Grogory's solution:
Instead of subclassing I call the following utility method right after I grab a reference to the drawer layout:
Try out this worked for me :
Set width of included layout
android:layout_width="320dp"
. For devices with different screen size you can dynamically set the width of this included layout.Another possible way to solve the issue without overriding too much:
}
If, at some point, support library is updated and mMinDrawerMargin is not there anymore you will get exception and fix problem before you publish your next update.
I didn't make measurements, but suppose there is not so many reflection to affect performance. Furthermore, it executes only per view creation.
PS it's strange why DrawerLayout is made so inflexible (I'm about private min margin) at this point...
Based on the Robert's Answer, you can use the
layout_marginLeft=-64dp
to solve this problem easily.However it doesn't seems to work anymore on Android 5.0 and above. So here's my solution that worked for me.
Basically, Add
android:layout_marginRight="-64dp"
to the rootDrawerLayout
so all the layout will go to the right for 64dp.Then I add the
layout_marginRight=64dp
to the content so it goes back to the original position. Then you can have a full drawer there.Nipper's FullDrawerLayout Class is just simply awesome.. it's performance is also faster than the default drawer how ever you can;t use it on devices with api that don't have view.getLayoutDirection(); (i'e : Class doesn;t work on all gingerbread devices )
so what i did was
replaced all
with the below code
I have my support library updated to the latest also have extended the fullDrawerlayout to the support navigational drawer. Now it works fine Gingerbread devices as well
Yes, you have to extend DrawerLayout and override some methods because
MIN_DRAWER_MARGIN
isprivate
Here is a possible solution: