2

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:

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

<?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>
Itiel Maimon
  • 834
  • 2
  • 9
  • 26
  • See http://stackoverflow.com/questions/30543605/how-to-add-footer-to-navigationview-android-support-design-library. – CoolMind Feb 07 '17 at 20:22

2 Answers2

2

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

Itiel Maimon
  • 834
  • 2
  • 9
  • 26
0

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>
Leonid
  • 4,953
  • 2
  • 10
  • 13