Issue
I have a Navigation drawer with three sections, Top,Middle and Bottom I need to make middle section to be scroll-able.
Here is my current layout.
<?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/navigation_drawer_container"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start">
<!-- begin Top Section-->
<android.support.design.widget.NavigationView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/background_black"
android:paddingLeft="50dp"
app:headerLayout="@layout/nav_header_main"
/>
<!--End Top Section-->
<!-- begin Middle Section-->
<android.support.design.widget.NavigationView
android:id="@+id/navigation_drawer_top"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="top"
android:background="@color/menuColor"
android:paddingLeft="50dp"
app:itemTextAppearance="@style/NavigationDrawerStyle"
app:menu="@menu/menu_navigation_drawer_top"
app:itemTextColor="@color/menuTextColour" />
<!-- End Middle Section-->
<!-- begin Bottom Section-->
<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@color/background_black"
app:headerLayout="@layout/nav_group_line"
app:itemTextColor="@color/menuTextColour">
<android.support.design.widget.NavigationView
android:id="@+id/navigation_drawer_bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@color/menuColor_bottom"
android:paddingLeft="50dp"
app:itemTextAppearance="@style/NavigationDrawerStyle"
app:itemTextColor="@color/menuTextColour"
app:menu="@menu/menu_navigation_drawer_bottom" />
</android.support.design.widget.NavigationView>
<!-- End Bottom Section-->
</android.support.design.widget.NavigationView>
How could I make meddle section scorll-able in my navigation view.
Solution
NavigationView gives you attr app:headerLayout for adding header for navigation. For adding footer just wrap the desired footer view in your NavigationView,
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
>
<LinearLayout
android:background="@android:color/darker_gray"
android:clickable="true"
android:id="@+id/ll_header"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical">
<TextView
android:gravity="center"
android:id="@+id/nav_header_textview"
android:layout_height="48dp"
android:layout_width="match_parent"
android:text="Your Header Text Here" />
</LinearLayout>
<android.support.design.widget.NavigationView
android:layout_below="@+id/ll_header"
android:layout_above="@+id/ll_footer"
android:id="@+id/navigation"
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:menu="@menu/my_navigation_items" >
</android.support.design.widget.NavigationView>
<LinearLayout
android:id="@+id/ll_footer"
android:background="@android:color/darker_gray"
android:layout_alignParentBottom="true"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical">
<TextView
android:gravity="center"
android:id="@+id/nav_footer_textview"
android:layout_height="48dp"
android:layout_width="match_parent"
android:text="Your Footer Text Here" />
</LinearLayout>
</RelativeLayout>
for example purpose,I have used TextView.
Answered By - Shrikant
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.