androidmaterial-designdrawermaterialdrawer

Remove left margin from materialdrawer


How to remove the space Mikepenz Material Drawer.I used custom layout for profile menu and drawer Items. I didnt set Margin or padding for those views. And i also tried activity horizontal margin to 0.enter image description here Help would be appreciated. same margin right side also. Profile menu is Ok. it has no problem.whereas draweritem facing the problem.

Below code is Profile Menu

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fitsSystemWindows="true"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="30dp"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <de.hdodenhof.circleimageview.CircleImageView
                android:id="@+id/imgUserProfileImage"
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:layout_margin="@dimen/min_margin"
                android:src="@drawable/parent" />

            <com.CustomTextView

                android:id="@+id/txtUserName"

                style="@style/label_text_primary"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:padding="10dp"
                android:text="Noorul"
                app:font="@string/montserrat_semi_bold" />
        </LinearLayout>

        <View
            android:layout_width="match_parent"
            android:layout_height="0.3dp"
            android:layout_marginTop="@dimen/min_margin"
            android:layout_marginLeft="@dimen/min_margin"
            android:background="#999999" />
    </LinearLayout>


</LinearLayout>

And Below Code is for Drawer Item Menu

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/lnrSecond_menu"
    android:layout_width="match_parent"
    android:layout_height="@dimen/material_drawer_item_secondary"
    android:orientation="horizontal">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent">

        <View
            android:id="@+id/view"
            android:layout_width="3dp"
            android:layout_height="match_parent"
            android:background="@color/primary"
            android:visibility="gone"/>

    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:gravity="center">

        <ImageView
            android:id="@+id/material_drawer_icon"
            android:layout_width="@dimen/profile_img"
            android:layout_height="@dimen/profile_img"
            android:padding="@dimen/most_most_normal_margin"
            android:src="@mipmap/ic_launcher" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:gravity="center_vertical|start"
        android:orientation="vertical">

        <com.CustomTextView
            android:id="@+id/material_drawer_name"
            style="@style/label_text_secondary"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center_vertical|start"
            android:textDirection="anyRtl"
            android:text="Some Secondary Text"
            app:font="@string/montserrat_regular"
            />

        <com.CustomTextView
            android:id="@+id/material_drawer_description"
            style="@style/label_text_secondary"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:singleLine="true"
            android:visibility="gone"
            app:font="@string/montserrat_regular"
            android:text="Some drawer text" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/material_drawer_badge_container"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:gravity="right|center">

        <com.CustomTextView
            android:id="@+id/txtMenuBadge"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="@dimen/min_margin"
            android:gravity="center"
            android:text="99" />
    </LinearLayout>

</LinearLayout>

Where I made the Mistake? Help me i will be grateful to you guys.


Solution

  • The drawer adds this padding because it is default for all items inside the Material Design Guidelines. As there is an issue with API 17 I have to set this programatically in this line: https://github.com/mikepenz/MaterialDrawer/blob/develop/library/src/main/java/com/mikepenz/materialdrawer/model/BasePrimaryDrawerItem.java#L104

    You might also want to post the DrawerItems you use, as the screenshot does not look like you use the default items.

    If you already create your own CustomDrawerItem you just want to set the padding to 0px again (If you extend from the BasePrimaryDrawerItem) If you do not extend from it you should be fine.

    The drawer does not set this padding on the items anywhere else than here.