Reputation: 1307
I'm following the post "Android design library NavigationView with footer" to add buttons at the bottom of NavigationView. The problem is that only the last NavigationView appears and it's occuping the entire screen height.
Here is my layout:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Activity here -->
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start">
<android.support.design.widget.NavigationView
android:id="@+id/navigation_menu_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="top"
app:menu="@menu/menu_drawer"/>
<android.support.design.widget.NavigationView
android:id="@+id/navigation_footer_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:menu="@menu/menu_drawer_footer"/>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
Here is the result:
How can i fix this?
Upvotes: 11
Views: 12322
Reputation: 630
The simplest answer is to add a button inside the Drawer layout and set it gravity to bottom in the navigationview.xml
as easy as that !!! here is the code.
<android.support.design.widget.NavigationView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/navigation"
android:layout_width="200dp"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/navigation_header"
app:menu="@menu/menu_navigation"
android:layout_alignParentTop="true">
<Button
android:id="@+id/btn_sing_in"
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="@string/sign_in"
android:layout_gravity="bottom"
/>
</android.support.design.widget.NavigationView>
Upvotes: 17
Reputation: 764
Weights and margins may need to be added or tweaked depending on how many items you want top and bottom, but this should be what you're looking for:
<android.support.design.widget.NavigationView
android:id="@+id/navigation_drawer_container"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="10">
<android.support.design.widget.NavigationView
android:id="@+id/navigation_drawer"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="top"
android:layout_weight="8"
app:menu="@menu/drawer" />
<android.support.design.widget.NavigationView
android:id="@+id/navigation_drawer_bottom"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="2"
android:layout_gravity="bottom"
app:menu="@menu/drawer_footer" />
</LinearLayout>
</android.support.design.widget.NavigationView>
Hope this helps :)
Upvotes: 12