如何向导航抽屉Android的菜单项左/右设置无边距

时间:2018-06-04 13:13:49

标签: android navigation-drawer menuitem

我用导航抽屉编写应用程序代码。我有一个菜单列表与自定义菜单项。每个项目,左边都有指示器,imageview和textview。抽屉布局工作正常,但它为菜单列表的每个项目创建左/右边距。 这是抽屉布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/drawer_layout_nav"
    tools:context="com.gem.timekeeper.screen.main.leftnavigation.MainActivity">

    <include layout="@layout/content_main" />

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@color/colorPrimary"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/menu_navigation_drawer" >
        <android.support.constraint.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:clickable="true"
            >
            <android.support.constraint.Guideline
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:layout_constraintGuide_percent="0.06"
                android:orientation="vertical"
                android:id="@+id/gl_v_6"/>
            <android.support.constraint.Guideline
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:layout_constraintGuide_percent="0.94"
                android:orientation="vertical"
                android:id="@+id/gl_v_94"/>
            <android.support.constraint.Guideline
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:layout_constraintGuide_percent="0.8"
                android:orientation="horizontal"
                android:id="@+id/gl_h_80"/>
            <Button
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:background="@drawable/border_button_logout_nav"
                android:id="@+id/btn_unlock_Nav"
                app:layout_constraintStart_toEndOf="@id/gl_v_6"
                app:layout_constraintEnd_toStartOf="@id/gl_v_94"
                app:layout_constraintBottom_toTopOf="@id/gl_h_80"
                android:fontFamily="sans-serif-medium"
                android:textStyle="normal"
                android:textColor="@color/colorPrimary"
                android:letterSpacing="0.03"
                android:text="Đăng xuất"/>
        </android.support.constraint.ConstraintLayout>
    </android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>

我自定义菜单项:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:tools="http://schemas.android.com/tools"
    android:background="@color/colorPrimaryDark"
        android:orientation="horizontal">

    <ImageView
        android:layout_gravity="center"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_cham_cong"
         />
    <TextView
        android:layout_gravity="center"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="@dimen/margin_medium"
        android:textSize="16sp"
        android:fontFamily="sans-serif"
        android:textStyle="normal"
        android:textColor="#ffffff"
        android:letterSpacing="0.03"
        android:text="@string/common_mark_work_point"
        android:id="@+id/tv_mark_work_point_left_nav"
       />
</LinearLayout>

但是在屏幕上,菜单项有左右边距。 enter image description here 我想删除左/右边距并添加左指示符。我怎样才能做到这一点。救救我!

0 个答案:

没有答案