从 Materialdrawer 中删除左边距

Remove left margin from materialdrawer

如何删除 space Mikepenz Material Drawer.I 用于配置文件菜单和抽屉项目的自定义布局。我没有为这些视图设置边距或填充。我也试过 activity 水平边距为 0. 帮助将不胜感激。同样的保证金右侧也。配置文件菜单正常。它没有 problem.whereas 个面临问题的抽屉。

下面的代码是配置文件菜单

 <?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>

下面的代码用于抽屉项目菜单

    <?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>

我在哪里犯了错误?帮助我,我将不胜感激。

抽屉添加这个 padding 因为它是 Material Design Guidelines 内所有项目的默认设置。由于 API 17 存在问题,因此我必须在此行中以编程方式进行设置: https://github.com/mikepenz/MaterialDrawer/blob/develop/library/src/main/java/com/mikepenz/materialdrawer/model/BasePrimaryDrawerItem.java#L104

您可能还想 post 您使用的 DrawerItem,因为屏幕截图看起来不像您使用默认项目。

如果您已经创建了自己的 CustomDrawerItem,您只想再次将填充设置为 0px(如果您从 BasePrimaryDrawerItem 扩展)如果您不从它扩展,您应该没问题。

抽屉不会在除此处以外的任何地方的项目上设置此填充。