Add a ListView or RecyclerView to new NavigationView
I am using the new NavigationView from revision 22.2.0 of the support library by Google. It works perfectly fine to generate a navigation drawer populated using a menu res.
I was wondering is it possible to add a ListView or RecyclerView to the navigation drawer so that it can be populated using my custom adapter code, which allows for far greater flexibility than menu resources.
Here is my current XML:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
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:fitsSystemWindows="true"
tools:context=".MainActivity">
<FrameLayout
android:id="@+id/content_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/main_toolbar" />
</FrameLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/navigation_drawer_header"
app:menu="@menu/menu_navigation_drawer" />
</android.support.v4.widget.DrawerLayout>
Where in my XML would I add the ListView or RecyclerView?
EDIT
As per Basant's suggestion, I nested a ListView into the NavigationView. You lose the ability to inflate from a menu res (as far as I know) but it succeeds in what I want it to do. The header XML is unchanged, it is just included into XML.
New code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<FrameLayout
android:id="@+id/content_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/main_toolbar" />
</FrameLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="@+id/navigation_drawer_header_include"
layout="@layout/navigation_drawer_header" />
<ListView
android:id="@+id/navigation_drawer_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/navigation_drawer_header_include"/>
</RelativeLayout>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
android listview android-recyclerview navigationview
add a comment |
I am using the new NavigationView from revision 22.2.0 of the support library by Google. It works perfectly fine to generate a navigation drawer populated using a menu res.
I was wondering is it possible to add a ListView or RecyclerView to the navigation drawer so that it can be populated using my custom adapter code, which allows for far greater flexibility than menu resources.
Here is my current XML:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
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:fitsSystemWindows="true"
tools:context=".MainActivity">
<FrameLayout
android:id="@+id/content_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/main_toolbar" />
</FrameLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/navigation_drawer_header"
app:menu="@menu/menu_navigation_drawer" />
</android.support.v4.widget.DrawerLayout>
Where in my XML would I add the ListView or RecyclerView?
EDIT
As per Basant's suggestion, I nested a ListView into the NavigationView. You lose the ability to inflate from a menu res (as far as I know) but it succeeds in what I want it to do. The header XML is unchanged, it is just included into XML.
New code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<FrameLayout
android:id="@+id/content_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/main_toolbar" />
</FrameLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="@+id/navigation_drawer_header_include"
layout="@layout/navigation_drawer_header" />
<ListView
android:id="@+id/navigation_drawer_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/navigation_drawer_header_include"/>
</RelativeLayout>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
android listview android-recyclerview navigationview
add a comment |
I am using the new NavigationView from revision 22.2.0 of the support library by Google. It works perfectly fine to generate a navigation drawer populated using a menu res.
I was wondering is it possible to add a ListView or RecyclerView to the navigation drawer so that it can be populated using my custom adapter code, which allows for far greater flexibility than menu resources.
Here is my current XML:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
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:fitsSystemWindows="true"
tools:context=".MainActivity">
<FrameLayout
android:id="@+id/content_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/main_toolbar" />
</FrameLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/navigation_drawer_header"
app:menu="@menu/menu_navigation_drawer" />
</android.support.v4.widget.DrawerLayout>
Where in my XML would I add the ListView or RecyclerView?
EDIT
As per Basant's suggestion, I nested a ListView into the NavigationView. You lose the ability to inflate from a menu res (as far as I know) but it succeeds in what I want it to do. The header XML is unchanged, it is just included into XML.
New code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<FrameLayout
android:id="@+id/content_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/main_toolbar" />
</FrameLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="@+id/navigation_drawer_header_include"
layout="@layout/navigation_drawer_header" />
<ListView
android:id="@+id/navigation_drawer_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/navigation_drawer_header_include"/>
</RelativeLayout>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
android listview android-recyclerview navigationview
I am using the new NavigationView from revision 22.2.0 of the support library by Google. It works perfectly fine to generate a navigation drawer populated using a menu res.
I was wondering is it possible to add a ListView or RecyclerView to the navigation drawer so that it can be populated using my custom adapter code, which allows for far greater flexibility than menu resources.
Here is my current XML:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
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:fitsSystemWindows="true"
tools:context=".MainActivity">
<FrameLayout
android:id="@+id/content_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/main_toolbar" />
</FrameLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/navigation_drawer_header"
app:menu="@menu/menu_navigation_drawer" />
</android.support.v4.widget.DrawerLayout>
Where in my XML would I add the ListView or RecyclerView?
EDIT
As per Basant's suggestion, I nested a ListView into the NavigationView. You lose the ability to inflate from a menu res (as far as I know) but it succeeds in what I want it to do. The header XML is unchanged, it is just included into XML.
New code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<FrameLayout
android:id="@+id/content_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/main_toolbar" />
</FrameLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="@+id/navigation_drawer_header_include"
layout="@layout/navigation_drawer_header" />
<ListView
android:id="@+id/navigation_drawer_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/navigation_drawer_header_include"/>
</RelativeLayout>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
android listview android-recyclerview navigationview
android listview android-recyclerview navigationview
edited Jun 22 '15 at 11:34
nabir
asked Jun 22 '15 at 10:52
nabirnabir
5472616
5472616
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
You can just nest the ListView
or RecyclerView
inside the NavigationView
.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
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:fitsSystemWindows="true"
tools:context=".MainActivity">
<FrameLayout
android:id="@+id/content_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/main_toolbar" />
</FrameLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"/>
<ListView
android:id="@+id/menuList"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</android.support.v4.widget.DrawerLayout>
NOTE: Keep in mind that if you use use a ListView inside it, you can't use the NavigationView's header. You will have to use the header view of the ListView that you are adding. Don't forget to remove the app:menu
and app:header
fields.
Hello, I've tried that but the nav drawer breaks in the sense the navigation items are no longer clickable. Just saw your NOTE edit, I'll try that now.
– nabir
Jun 22 '15 at 11:14
2
I think you should not use the NavigationMenu in that case. Simply use a ListView or a more complex layout if you need, in place of a NavigationMenu. That will give you more flexibility.
– Basant Singh
Jun 22 '15 at 11:20
The reason I want to use NavigationView is due to built in scrim handling to give it that more material look, I have applied your suggestion and it seems to work. I will update my post to show the new code.
– nabir
Jun 22 '15 at 11:27
Check out the accepted answer here: stackoverflow.com/questions/26745300/…
– Basant Singh
Jun 22 '15 at 11:30
I was previously using that but the new NavigationView has that built in and I prefer using the new view since it is part of the library.
– nabir
Jun 22 '15 at 11:35
add a comment |
If you want to adding views inside the NavigationView you can do something like this. This way you have no restriction of adding Header on your NavigtionView with ListView.
<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="false"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/nav_header_main"
android:id="@+id/my"
/>
<ListView
android:layout_weight="7"
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/list_view_inside_nav"></ListView>
</LinearLayout>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
That look something like this
This will not scroll the header view like the Navigation View does
– Killer
Apr 12 '16 at 14:22
1
yes, you can put them into linear layout with orientation vertical and then put in into scrollview with parameter fillViewPort = true
– deadfish
Jun 1 '16 at 12:59
1
It tried but AFAIK (remember) whenever i am opening navigation drawer containing recycler view instead of listview the view don't show header rather than it was scrolled down to recycler view. @deadfish
– Killer
Aug 1 '16 at 16:40
@Shubham have you add header above the recyclerview inside navigationview
– redblood
Aug 3 '16 at 4:27
seems like it works for me
– Killer
Aug 3 '16 at 7:29
|
show 1 more comment
In response to Shubham's comment
This will not scroll the header view like the Navigation View does
I solved it by putting the LinearLayout
inside a NestedScrollView
. Now it scrolls properly with the header.
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/nav_header_main" />
<android.support.v7.widget.RecyclerView
android:id="@+id/nav_list"
android:layout_width="match_parent"
android:layout_height="@dimen/weight_based_height"
android:layout_weight="1"
android:nestedScrollingEnabled="false"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
add a comment |
Try this way
<android.support.design.widget.NavigationView
android:id="@+id/navigation"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/nav_header" />
<ListView
android:id="@+id/lst_menu_items"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f30978114%2fadd-a-listview-or-recyclerview-to-new-navigationview%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can just nest the ListView
or RecyclerView
inside the NavigationView
.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
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:fitsSystemWindows="true"
tools:context=".MainActivity">
<FrameLayout
android:id="@+id/content_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/main_toolbar" />
</FrameLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"/>
<ListView
android:id="@+id/menuList"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</android.support.v4.widget.DrawerLayout>
NOTE: Keep in mind that if you use use a ListView inside it, you can't use the NavigationView's header. You will have to use the header view of the ListView that you are adding. Don't forget to remove the app:menu
and app:header
fields.
Hello, I've tried that but the nav drawer breaks in the sense the navigation items are no longer clickable. Just saw your NOTE edit, I'll try that now.
– nabir
Jun 22 '15 at 11:14
2
I think you should not use the NavigationMenu in that case. Simply use a ListView or a more complex layout if you need, in place of a NavigationMenu. That will give you more flexibility.
– Basant Singh
Jun 22 '15 at 11:20
The reason I want to use NavigationView is due to built in scrim handling to give it that more material look, I have applied your suggestion and it seems to work. I will update my post to show the new code.
– nabir
Jun 22 '15 at 11:27
Check out the accepted answer here: stackoverflow.com/questions/26745300/…
– Basant Singh
Jun 22 '15 at 11:30
I was previously using that but the new NavigationView has that built in and I prefer using the new view since it is part of the library.
– nabir
Jun 22 '15 at 11:35
add a comment |
You can just nest the ListView
or RecyclerView
inside the NavigationView
.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
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:fitsSystemWindows="true"
tools:context=".MainActivity">
<FrameLayout
android:id="@+id/content_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/main_toolbar" />
</FrameLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"/>
<ListView
android:id="@+id/menuList"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</android.support.v4.widget.DrawerLayout>
NOTE: Keep in mind that if you use use a ListView inside it, you can't use the NavigationView's header. You will have to use the header view of the ListView that you are adding. Don't forget to remove the app:menu
and app:header
fields.
Hello, I've tried that but the nav drawer breaks in the sense the navigation items are no longer clickable. Just saw your NOTE edit, I'll try that now.
– nabir
Jun 22 '15 at 11:14
2
I think you should not use the NavigationMenu in that case. Simply use a ListView or a more complex layout if you need, in place of a NavigationMenu. That will give you more flexibility.
– Basant Singh
Jun 22 '15 at 11:20
The reason I want to use NavigationView is due to built in scrim handling to give it that more material look, I have applied your suggestion and it seems to work. I will update my post to show the new code.
– nabir
Jun 22 '15 at 11:27
Check out the accepted answer here: stackoverflow.com/questions/26745300/…
– Basant Singh
Jun 22 '15 at 11:30
I was previously using that but the new NavigationView has that built in and I prefer using the new view since it is part of the library.
– nabir
Jun 22 '15 at 11:35
add a comment |
You can just nest the ListView
or RecyclerView
inside the NavigationView
.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
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:fitsSystemWindows="true"
tools:context=".MainActivity">
<FrameLayout
android:id="@+id/content_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/main_toolbar" />
</FrameLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"/>
<ListView
android:id="@+id/menuList"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</android.support.v4.widget.DrawerLayout>
NOTE: Keep in mind that if you use use a ListView inside it, you can't use the NavigationView's header. You will have to use the header view of the ListView that you are adding. Don't forget to remove the app:menu
and app:header
fields.
You can just nest the ListView
or RecyclerView
inside the NavigationView
.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
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:fitsSystemWindows="true"
tools:context=".MainActivity">
<FrameLayout
android:id="@+id/content_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/main_toolbar" />
</FrameLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"/>
<ListView
android:id="@+id/menuList"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</android.support.v4.widget.DrawerLayout>
NOTE: Keep in mind that if you use use a ListView inside it, you can't use the NavigationView's header. You will have to use the header view of the ListView that you are adding. Don't forget to remove the app:menu
and app:header
fields.
answered Jun 22 '15 at 11:05
Basant SinghBasant Singh
3,44112138
3,44112138
Hello, I've tried that but the nav drawer breaks in the sense the navigation items are no longer clickable. Just saw your NOTE edit, I'll try that now.
– nabir
Jun 22 '15 at 11:14
2
I think you should not use the NavigationMenu in that case. Simply use a ListView or a more complex layout if you need, in place of a NavigationMenu. That will give you more flexibility.
– Basant Singh
Jun 22 '15 at 11:20
The reason I want to use NavigationView is due to built in scrim handling to give it that more material look, I have applied your suggestion and it seems to work. I will update my post to show the new code.
– nabir
Jun 22 '15 at 11:27
Check out the accepted answer here: stackoverflow.com/questions/26745300/…
– Basant Singh
Jun 22 '15 at 11:30
I was previously using that but the new NavigationView has that built in and I prefer using the new view since it is part of the library.
– nabir
Jun 22 '15 at 11:35
add a comment |
Hello, I've tried that but the nav drawer breaks in the sense the navigation items are no longer clickable. Just saw your NOTE edit, I'll try that now.
– nabir
Jun 22 '15 at 11:14
2
I think you should not use the NavigationMenu in that case. Simply use a ListView or a more complex layout if you need, in place of a NavigationMenu. That will give you more flexibility.
– Basant Singh
Jun 22 '15 at 11:20
The reason I want to use NavigationView is due to built in scrim handling to give it that more material look, I have applied your suggestion and it seems to work. I will update my post to show the new code.
– nabir
Jun 22 '15 at 11:27
Check out the accepted answer here: stackoverflow.com/questions/26745300/…
– Basant Singh
Jun 22 '15 at 11:30
I was previously using that but the new NavigationView has that built in and I prefer using the new view since it is part of the library.
– nabir
Jun 22 '15 at 11:35
Hello, I've tried that but the nav drawer breaks in the sense the navigation items are no longer clickable. Just saw your NOTE edit, I'll try that now.
– nabir
Jun 22 '15 at 11:14
Hello, I've tried that but the nav drawer breaks in the sense the navigation items are no longer clickable. Just saw your NOTE edit, I'll try that now.
– nabir
Jun 22 '15 at 11:14
2
2
I think you should not use the NavigationMenu in that case. Simply use a ListView or a more complex layout if you need, in place of a NavigationMenu. That will give you more flexibility.
– Basant Singh
Jun 22 '15 at 11:20
I think you should not use the NavigationMenu in that case. Simply use a ListView or a more complex layout if you need, in place of a NavigationMenu. That will give you more flexibility.
– Basant Singh
Jun 22 '15 at 11:20
The reason I want to use NavigationView is due to built in scrim handling to give it that more material look, I have applied your suggestion and it seems to work. I will update my post to show the new code.
– nabir
Jun 22 '15 at 11:27
The reason I want to use NavigationView is due to built in scrim handling to give it that more material look, I have applied your suggestion and it seems to work. I will update my post to show the new code.
– nabir
Jun 22 '15 at 11:27
Check out the accepted answer here: stackoverflow.com/questions/26745300/…
– Basant Singh
Jun 22 '15 at 11:30
Check out the accepted answer here: stackoverflow.com/questions/26745300/…
– Basant Singh
Jun 22 '15 at 11:30
I was previously using that but the new NavigationView has that built in and I prefer using the new view since it is part of the library.
– nabir
Jun 22 '15 at 11:35
I was previously using that but the new NavigationView has that built in and I prefer using the new view since it is part of the library.
– nabir
Jun 22 '15 at 11:35
add a comment |
If you want to adding views inside the NavigationView you can do something like this. This way you have no restriction of adding Header on your NavigtionView with ListView.
<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="false"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/nav_header_main"
android:id="@+id/my"
/>
<ListView
android:layout_weight="7"
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/list_view_inside_nav"></ListView>
</LinearLayout>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
That look something like this
This will not scroll the header view like the Navigation View does
– Killer
Apr 12 '16 at 14:22
1
yes, you can put them into linear layout with orientation vertical and then put in into scrollview with parameter fillViewPort = true
– deadfish
Jun 1 '16 at 12:59
1
It tried but AFAIK (remember) whenever i am opening navigation drawer containing recycler view instead of listview the view don't show header rather than it was scrolled down to recycler view. @deadfish
– Killer
Aug 1 '16 at 16:40
@Shubham have you add header above the recyclerview inside navigationview
– redblood
Aug 3 '16 at 4:27
seems like it works for me
– Killer
Aug 3 '16 at 7:29
|
show 1 more comment
If you want to adding views inside the NavigationView you can do something like this. This way you have no restriction of adding Header on your NavigtionView with ListView.
<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="false"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/nav_header_main"
android:id="@+id/my"
/>
<ListView
android:layout_weight="7"
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/list_view_inside_nav"></ListView>
</LinearLayout>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
That look something like this
This will not scroll the header view like the Navigation View does
– Killer
Apr 12 '16 at 14:22
1
yes, you can put them into linear layout with orientation vertical and then put in into scrollview with parameter fillViewPort = true
– deadfish
Jun 1 '16 at 12:59
1
It tried but AFAIK (remember) whenever i am opening navigation drawer containing recycler view instead of listview the view don't show header rather than it was scrolled down to recycler view. @deadfish
– Killer
Aug 1 '16 at 16:40
@Shubham have you add header above the recyclerview inside navigationview
– redblood
Aug 3 '16 at 4:27
seems like it works for me
– Killer
Aug 3 '16 at 7:29
|
show 1 more comment
If you want to adding views inside the NavigationView you can do something like this. This way you have no restriction of adding Header on your NavigtionView with ListView.
<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="false"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/nav_header_main"
android:id="@+id/my"
/>
<ListView
android:layout_weight="7"
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/list_view_inside_nav"></ListView>
</LinearLayout>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
That look something like this
If you want to adding views inside the NavigationView you can do something like this. This way you have no restriction of adding Header on your NavigtionView with ListView.
<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="false"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/nav_header_main"
android:id="@+id/my"
/>
<ListView
android:layout_weight="7"
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/list_view_inside_nav"></ListView>
</LinearLayout>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
That look something like this
edited Oct 22 '15 at 21:50
Orest Hera
5,97621330
5,97621330
answered Oct 22 '15 at 21:29
redbloodredblood
313315
313315
This will not scroll the header view like the Navigation View does
– Killer
Apr 12 '16 at 14:22
1
yes, you can put them into linear layout with orientation vertical and then put in into scrollview with parameter fillViewPort = true
– deadfish
Jun 1 '16 at 12:59
1
It tried but AFAIK (remember) whenever i am opening navigation drawer containing recycler view instead of listview the view don't show header rather than it was scrolled down to recycler view. @deadfish
– Killer
Aug 1 '16 at 16:40
@Shubham have you add header above the recyclerview inside navigationview
– redblood
Aug 3 '16 at 4:27
seems like it works for me
– Killer
Aug 3 '16 at 7:29
|
show 1 more comment
This will not scroll the header view like the Navigation View does
– Killer
Apr 12 '16 at 14:22
1
yes, you can put them into linear layout with orientation vertical and then put in into scrollview with parameter fillViewPort = true
– deadfish
Jun 1 '16 at 12:59
1
It tried but AFAIK (remember) whenever i am opening navigation drawer containing recycler view instead of listview the view don't show header rather than it was scrolled down to recycler view. @deadfish
– Killer
Aug 1 '16 at 16:40
@Shubham have you add header above the recyclerview inside navigationview
– redblood
Aug 3 '16 at 4:27
seems like it works for me
– Killer
Aug 3 '16 at 7:29
This will not scroll the header view like the Navigation View does
– Killer
Apr 12 '16 at 14:22
This will not scroll the header view like the Navigation View does
– Killer
Apr 12 '16 at 14:22
1
1
yes, you can put them into linear layout with orientation vertical and then put in into scrollview with parameter fillViewPort = true
– deadfish
Jun 1 '16 at 12:59
yes, you can put them into linear layout with orientation vertical and then put in into scrollview with parameter fillViewPort = true
– deadfish
Jun 1 '16 at 12:59
1
1
It tried but AFAIK (remember) whenever i am opening navigation drawer containing recycler view instead of listview the view don't show header rather than it was scrolled down to recycler view. @deadfish
– Killer
Aug 1 '16 at 16:40
It tried but AFAIK (remember) whenever i am opening navigation drawer containing recycler view instead of listview the view don't show header rather than it was scrolled down to recycler view. @deadfish
– Killer
Aug 1 '16 at 16:40
@Shubham have you add header above the recyclerview inside navigationview
– redblood
Aug 3 '16 at 4:27
@Shubham have you add header above the recyclerview inside navigationview
– redblood
Aug 3 '16 at 4:27
seems like it works for me
– Killer
Aug 3 '16 at 7:29
seems like it works for me
– Killer
Aug 3 '16 at 7:29
|
show 1 more comment
In response to Shubham's comment
This will not scroll the header view like the Navigation View does
I solved it by putting the LinearLayout
inside a NestedScrollView
. Now it scrolls properly with the header.
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/nav_header_main" />
<android.support.v7.widget.RecyclerView
android:id="@+id/nav_list"
android:layout_width="match_parent"
android:layout_height="@dimen/weight_based_height"
android:layout_weight="1"
android:nestedScrollingEnabled="false"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
add a comment |
In response to Shubham's comment
This will not scroll the header view like the Navigation View does
I solved it by putting the LinearLayout
inside a NestedScrollView
. Now it scrolls properly with the header.
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/nav_header_main" />
<android.support.v7.widget.RecyclerView
android:id="@+id/nav_list"
android:layout_width="match_parent"
android:layout_height="@dimen/weight_based_height"
android:layout_weight="1"
android:nestedScrollingEnabled="false"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
add a comment |
In response to Shubham's comment
This will not scroll the header view like the Navigation View does
I solved it by putting the LinearLayout
inside a NestedScrollView
. Now it scrolls properly with the header.
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/nav_header_main" />
<android.support.v7.widget.RecyclerView
android:id="@+id/nav_list"
android:layout_width="match_parent"
android:layout_height="@dimen/weight_based_height"
android:layout_weight="1"
android:nestedScrollingEnabled="false"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
In response to Shubham's comment
This will not scroll the header view like the Navigation View does
I solved it by putting the LinearLayout
inside a NestedScrollView
. Now it scrolls properly with the header.
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/nav_header_main" />
<android.support.v7.widget.RecyclerView
android:id="@+id/nav_list"
android:layout_width="match_parent"
android:layout_height="@dimen/weight_based_height"
android:layout_weight="1"
android:nestedScrollingEnabled="false"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
edited Sep 30 '18 at 17:27
answered Nov 6 '16 at 5:35
IsaiahJIsaiahJ
319417
319417
add a comment |
add a comment |
Try this way
<android.support.design.widget.NavigationView
android:id="@+id/navigation"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/nav_header" />
<ListView
android:id="@+id/lst_menu_items"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
add a comment |
Try this way
<android.support.design.widget.NavigationView
android:id="@+id/navigation"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/nav_header" />
<ListView
android:id="@+id/lst_menu_items"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
add a comment |
Try this way
<android.support.design.widget.NavigationView
android:id="@+id/navigation"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/nav_header" />
<ListView
android:id="@+id/lst_menu_items"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
Try this way
<android.support.design.widget.NavigationView
android:id="@+id/navigation"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/nav_header" />
<ListView
android:id="@+id/lst_menu_items"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
edited Dec 19 '18 at 10:48
Naveen T P
3,47611119
3,47611119
answered Dec 29 '16 at 9:24
Mahendran CandyMahendran Candy
8221216
8221216
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f30978114%2fadd-a-listview-or-recyclerview-to-new-navigationview%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown