简体   繁体   English

如何在导航抽屉中的最后一项下添加一些空间?

[英]How to add some space under the last item in a Navigation Drawer?

I have a Navigation Drawer that contains several items.我有一个包含多个项目的导航抽屉。 I added a button on the bottom of the Navigation Drawer.我在导航抽屉的底部添加了一个按钮。 The problem is that in small size screens the button covers the last item in the Drawer.问题在于,在小尺寸屏幕中,按钮覆盖了抽屉中的最后一项。

How can I add some space under the last item so the button won't cover anything?如何在最后一个项目下添加一些空间,以便按钮不会覆盖任何内容?

activity_main.xml:活动_main.xml:

<?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:id="@+id/drawer_layout"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:fitsSystemWindows="true"
 tools:openDrawer="start">

  <include
    layout="@layout/app_bar_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

  <android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/nav_header_main"
    app:menu="@menu/activity_main_drawer" >

    <Button
        android:id="@+id/remove_ads_button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:background="@color/red"
        android:text="@string/remove_ads"
        android:textColor="@color/white"
        android:textSize="15sp" />

  </android.support.design.widget.NavigationView>

</android.support.v4.widget.DrawerLayout>

activity_main_drawer.xml: activity_main_drawer.xml:

<?xml version="1.0" encoding="utf-8"?>
<menu
 xmlns:android="http://schemas.android.com/apk/res/android">

 <group android:checkableBehavior="none">
    <item
        android:id="@+id/action_contact_us"
        android:icon="@drawable/ic_contact_us"
        android:title="@string/action_contact_us" />
    <item
        android:id="@+id/action_share"
        android:icon="@drawable/ic_share_24dp"
        android:title="@string/action_share" />
    <item
        android:id="@+id/action_rate_us"
        android:icon="@drawable/ic_rate_us_24dp"
        android:title="@string/action_rate_us" />
    <item
        android:id="@+id/action_follow_us"
        android:icon="@drawable/ic_follow_us_24dp"
        android:title="@string/action_follow_us" />
    <item
        android:id="@+id/action_help"
        android:icon="@drawable/ic_help_name"
        android:title="@string/action_help" />
    <item
        android:id="@+id/action_about_us"
        android:icon="@drawable/ic_info_24dp"
        android:title="@string/action_about_us" />
    <item
        android:id="@+id/action_settings"
        android:icon="@drawable/ic_settings_24dp"
        android:title="@string/action_settings" />
 </group>

</menu>

I came up with an idea how to do it and it worked for me.我想出了一个主意如何去做,它对我有用。 What I needed to do is to add one more Item to the Drawer and then disable it.我需要做的是在抽屉中再添加一个项目,然后禁用它。

The code is:代码是:

 <item
    android:title=""
    android:enabled="false" >
</item>

Very simple and easy!!!非常简单好用!!!

May be you can try something like this也许你可以尝试这样的事情

    <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        tools:openDrawer="start">
        <include
            layout="@layout/app_bar_main"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
        <android.support.design.widget.NavigationView
            android:id="@+id/nav_view"
            android:layout_width="@dimen/nav_drawer_width"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:fitsSystemWindows="true">
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
                <Button
                    android:id="@+id/remove_ads_button"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_alignParentBottom="true"
                    android:background="@color/red"
                    android:text="@string/remove_ads"
                    android:textColor="@color/white"
                    android:textSize="15sp" />
                <ScrollView
                    android:id="@+id/my_scroll_view"
                    android:layout_above="@id/remove_ads_button"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">
                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="vertical"
                        android:paddingBottom="@dimen/padding_10dp">

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

                        <TextView
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:text="@string/action_contact_us"
                            android:textSize="@dimen/text_30sp"
                            android:drawableRight="@drawable/ic_contact_us"
                            android:drawablePadding="8dp"/>
                            <!--another menu items-->

                    </LinearLayout>
                </ScrollView>


            </RelativeLayout>

        </android.support.design.widget.NavigationView>
    </android.support.v4.widget.DrawerLayout>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM