Navigation drawer and sliding panel in the same activity - android

I need to use navigation drawer for left side menu and sliding panel for right side menu. Is any option to use them together, on same layout?
I have following layout for my activity:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/side_menu_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/oliveGreen"/>
<ListView android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_marginStart="30dp"
android:layout_marginLeft="30dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:background="#color/gray"/>
</android.support.v4.widget.DrawerLayout>
and navigation drawer (obviously) works but I cannot figure out how to add sliding panel.
Any advice would be appreciated.
Thanks in advance.
EDIT:
This is what I want to achieve:

Add another child View/ViewGroup inside DrawerLayout with layout_gravity set to end - this will act as your sliding panel.
Try code below, sliding panel is another ListView in this case but you can use <fragment /> or <LinearLayout /> etc instead:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/side_menu_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/oliveGreen"/>
<ListView android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_marginStart="30dp"
android:layout_marginLeft="30dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:background="#color/gray"/>
<ListView android:id="#+id/sliding_panel"
android:layout_width="240dp"
android:layout_marginStart="30dp"
android:layout_marginLeft="30dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:background="#color/gray"/>
</android.support.v4.widget.DrawerLayout>

Related

My emulator shows just Listview on entire screen. even its width is limited to 240dp

I am using drawer layout and Listview is using as drawer.
My emulator just showing Listview as width set to match parent even it's set to 240dp.
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/drawer Layout"
android:background="#000000">
<ListView
android:layout_width="240dp"
android:layout_height="match_parent"
android:id="#+id/drawerList"
android:background="#color/colorAccent"/>
<FrameLayout
android:layout_width="250dp"
android:layout_height="match_parent"
android:id="#+id/fragmentContainer"
android:background="#ffffff"
android:choiceMode="singleChoice"
android:dividerHeight="0dp"
android:divider="#android:color/transparent"/>
</android.support.v4.widget.DrawerLayout>
Drawer layouts are usually hidden outside of the screen until you open them. Try opening the drawer by swiping from the side.
You must use NavigationView inside DrawerLayout and limit width in NavigationView.
Example layout structure is like that , there is 2 different usage of NavigationView :
<?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"
android:id="#+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<!-- you can add extra views in DrawerLayout -->
<include layout="#layout/content_home"/>
<android.support.design.widget.NavigationView
android:id="#+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:layout_gravity="start"
app:menu="#menu/homepage_leftdrawer"/>
<!-- you can use listview, recyclerview etc in navigationview -->
<android.support.design.widget.NavigationView
android:id="#+id/navigation_view2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:fitsSystemWindows="false"
app:headerLayout="#layout/homepage_right_header"
android:layout_gravity="end">
<ListView
android:id="#+id/list_slidermenu"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:choiceMode="singleChoice"
android:dividerHeight="1dp"
android:layout_marginTop="80dp" />
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>

ListView doesn't work when i have DrawerLayout in Acivity Layout

Drawerlayout conflict with ListView in Activity Layout. but only ListView works fine and only DrawerLayout works fine too. problem is if they work together
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/diary_layout"
android:background="#drawable/activebg">
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="30dp"
android:layout_marginTop="20dp"
android:listSelector="#android:color/transparent"
android:id="#+id/diary_list">
</ListView>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView android:id="#+id/navList"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:background="#111"/>
</android.support.v4.widget.DrawerLayout>
</RelativeLayout>
in this situation when i have drawer layout listview doesn't work
(not click, not scroll). if remove
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView android:id="#+id/navList"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:background="#111"/>
</android.support.v4.widget.DrawerLayout>
this block listview works fine. can anyone help me ?
Difference is that, in my example i use ListView(not ScrollView), there is solved this problem
Android ScrollView not scrolling in Activity with Drawer Layout

Two Navigation Drawer on same Activity

Is it possible to configurate two Navigation Drawers on the same activity, one from the left and the other from the right?
You can use drawer layout
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- The navigation drawer -->
<ListView android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:background="#111"/>
<ListView android:id="#+id/right_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:background="#111"/>
</android.support.v4.widget.DrawerLayout>
ALso check the documantation https://developer.android.com/training/implementing-navigation/nav-drawer.html
Make sure you are using toolbar not action bar
Yes you can add two ListView inside your drawer layout, one listview should have gravity start and other have end.
yes
Can use two navigationdrawer
<android.support.v4.widget.DrawerLayout
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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawer_layout"
tools:context="PackageName.ActivityName">
<ScrollView
android:id="#+id/scrol_lay"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- your layout -->
</ScrollView>
<!-- First navigation drawer -->
<android.support.design.widget.NavigationView
android:id="#+id/navigation_view_main"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:menu="#menu/navigation_main_menu"
app:headerLayout="#layout/navigation_header"/>
<!-- Second navigation drawer -->
<android.support.design.widget.NavigationView
android:id="#+id/navigation_view_second"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="end"
app:menu="#menu/navigation_menu"
app:headerLayout="#layout/navigation_header"/>
</android.support.v4.widget.DrawerLayout>
For maximum customization,
In your xml, you can use a FrameLayout as a container
<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">
<FrameLayout
android:id="#+id/contDrawer"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.design.widget.NavigationView>
Now in your Activity, you can replace it with any fragment
getSupportFragmentManager().beginTransaction().replace(R.id.contDrawer, SideBarCustomerFragment.newInstance()).commit();
Now for two users, you can create 2 different fragments, You can check my boilerplate code for reference
https://github.com/hamzaahmedkhan/AndroidStructure/blob/master/app/src/main/java/com/android/structure/activities/HomeActivity.java
https://github.com/hamzaahmedkhan/AndroidStructure/blob/master/app/src/main/java/com/android/structure/activities/BaseActivity.java

How can I open navigation drawer from right side to left [duplicate]

This question already has answers here:
How to set Navigation Drawer to be opened from right to left
(15 answers)
Closed 4 years ago.
I want Open like in image from right to left
Here is my code where can i make change to open from right to left.
<FrameLayout
android:id="#+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
<ListView
android:id="#+id/drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#111"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp" />
In your main layout set your ListView gravity to end:
Use
android:layout_gravity="end"
layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/activity_messages"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<FrameLayout
android:id="#+id/activity_messages_content"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- The navigation drawer -->
<FrameLayout
android:id="#+id/activity_messages_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="end"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:background="#drawable/bg_background_gradient"/>
</android.support.v4.widget.DrawerLayout>
in activity :
mLayout = (DrawerLayout)findViewById(R.id.activity_messages);
mLayout.openDrawer(Gravity.RIGHT);

EditText inside of a DrawerLayout

I've been trying to set an EditText box inside of a DrawerLayout, but reading carefully through the Android Training Website, they explain that the DrawerLayout is allowed to have only two child views. If I would like to do something like the next code, How should I approach it?
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- The navigation drawer -->
<EditText
android:id="#+id/EditText01"
android:layout_width="240dp"
android:layout_height="match_parent"
android:hint="Search" >
</EditText>
<ListView android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:background="#111"/>
</android.support.v4.widget.DrawerLayout>
Do it like this:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- The navigation drawer -->
<LinearLayout
android:id="#+id/left_drawer"
android:layout_height="wrap_content"
android:layout_width="240dp"
android:orientation="vertical"
android:layout_gravity="start" >
<EditText
android:id="#+id/EditText01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Search" >
</EditText>
<ListView android:id="#+id/left_drawer_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:background="#111"/>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
In other words, whatever the first view is, will be set as the content view, and whatever the second view is will be set in the drawer. So simply add elements inside the second view for drawer, and first for content. Cheers :)

Categories

Resources