NavigationDrawer disable right swipe - android

I have DrawerLayout setup with a drawer on either side
<FrameLayout android:id="#+id/navigation_drawer"
android:layout_width="#dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start" />
<FrameLayout android:id="#+id/navigation_drawer_right"
android:layout_width="#dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="end" />
The right drawer is populated when a certain method is run, however, before that method is run I can swipe from the right and the screen dims but nothing shows (because the layout is empty until the method has been run).
How can I disable swipe from the right until the method has been run? I've seen solutions to fully disable any swiping, but that wouldn't work for me as the left drawer needs to always work (the setup right draw function is called when a particular option is selected on the left drawer).
Or, would there be a better way to do this? Maybe dynamically adding the right FrameLayout when the function is run?

This disables the swipe:
mDrawerLayout = (DrawerLayout) findViewById(R.id.navigation_drawer_right);
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
And to enable swipe:
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);

A bit updated answer.
You need to pass right drawer view to disable swipe on it.
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, findViewById(R.id.right_drawer));

Just to mention an interesting observation.
In case you are using a layout structure for having left AND right side menus like this one:
<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"
android:fitsSystemWindows="true">
<!-- MAIN CONTAINER -->
<include layout="#layout/content_home"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/toolbar"/>
<!-- LEFT SIDE MENU -->
<RelativeLayout
android:id="#+id/left_side_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:visibility="visible"
android:fitsSystemWindows="false"
android:background="#color/green">
<!-- put some menu items in here -->
</RelativeLayout>
<!-- RIGHT SIDE MENU -->
<RelativeLayout
android:id="#+id/right_side_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:visibility="visible"
android:fitsSystemWindows="false"
android:background="#color/gray">
<!-- put some items in here -->
</RelativeLayout>
You're gonna have some hard time trying to disable only one of the side menus
with statements like this one:
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, findViewById(R.id.right_drawer))
That will lock the whole DrawerLayout and you won't be able to swipe neither of the side menus.
Thus, the method proposed by #Alberto Maluje, under one of the answers above, will give you more flexibility.
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, GravityCompat.END);

Related

DrawerLayout with partially visible button

Sorry I couldn't figure out a better title.
I have an XML with a DrawerLayout like this:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Frame layout for fragment -->
<FrameLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="#+id/Fragment_Container" />
<!-- Need a button visible here that moves left and right with the drawer -->
<!-- This is a right side drawer-->
<LinearLayout
android:orientation="vertical"
android:layout_gravity="right"
android:gravity="center_vertical"
android:layout_width="101dp"
android:layout_height="match_parent">
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
I'd like to have a button that's visible at all times on the screen, that when clicked opens/closes the DrawerLayout, so it should move in sync with the drawer.
I've tried putting it inside the drawer and offsetting it to the left, but it just stays a part of it's content.
The only other options I'm considering now is making it detect drawer movement and make it manually slide accordingly.
Bonus issue: It should be shown on top of the fragment i.e it should have higher z-index than the fragment loaded.
Thanks

DrawerLayout with two drawers: Right one "jumping" when left one is opened?

My application has a DrawerLayout with two drawers in it, one on the left for nav and one on the right for notifications. When the application goes through a cold start and I swipe the left drawer open, the right drawer jumps from the far left of the screen to the right.
It looks like this: http://i.imgur.com/mhoJ7MZ.gifv
As shown in the video, I've tried using DrawerLayout's isDrawerOpen and isDrawerVisible methods to try to see if it actually thinks the right drawer is open when it's not (since it seems to be "closing" the drawer when the left one is opened), but I didn't get anything useful from that.
What's causing the weird jump?
My activity's XML is below, the full code is here.
<?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_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
...
</LinearLayout>
<LinearLayout
android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#ACFF0000"
android:gravity="center"
android:visibility="gone">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="LEFT DRAWER"
android:textSize="24sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/right_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="#AC00FF00"
android:gravity="center"
android:visibility="gone">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RIGHT DRAWER"
android:textSize="24sp" />
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
The issue comes from the android:visibility="gone" element on the LinearLayouts -- For some reason having visibility set to gone conflicts with the DrawerLayout's logic for if the view is showing or not, so it tries to hide it.
Taking that out of the XML causes everything to look the same (since DrawerLayout looks at the layout_gravity to decide which child views are drawers and hides them itself) and not have the weird jump.

How to make a Navigation Drawer with these functionalities in Android?

I want to implement an Android app which measures someone's performances in sport activities.
The problem which I have is that I must implement a sliding menu from the left side of the screen, where one can change the account on which the performances must be registered.
I don't know how to make the part which is show in this picture.
One can add a new user by clicking on add new user button, can edit the account by clicking on the pen, and switch to other account by clicking on it when it is inactive.
I've searched for info about how to do this but I didn't find anything related to this.
This is how my app must look:
Does anyone have an idea about how to do this or something similar to my issue?
You have to Go for Sliding menu lib.
you can use android DrawerLayout.
Please take look.
There is Suggestion of design for NavigationDrawer..............
This could help you to Create Layout like that...
First Create Navigation Drawer form Here : Creating a Navigation Drawer
and then change some code in Drawelayout.xml(which contains nav. drawer)
navDrawer.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/com.equest.cwely.act"
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" >
</FrameLayout>
<!-- The navigation drawer -->
<LinearLayout
android:id="#+id/drawer"
android:layout_width="300dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#color/actionbar_bg"
android:orientation="vertical" >
<include
android:id="#+id/nav_list_header"
layout="#layout/nav_profile" />
<ListView
android:id="#+id/drawer_list"
android:layout_width="300dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:layout_marginTop="10dp"
android:choiceMode="singleChoice"
android:divider="#55ffffff"
android:dividerHeight="0.5dp"
android:listSelector="#drawable/list_selector" />
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
Here,
<include/> : I have created one layout and added it into navDrawerLayout file...
<ListView/> : second Layout...........

Frame Layout fades away when opening navigation drawer

I am developing a mobile app in android for listing the most recent news. I have implemented the navigation drawer to select the categories. For this I have used fragments and frame layout. When I open navigation drawer the layout in the background seem to fade away or the screen brightennes gets darker.
Is there a way to make me possible to open the navigation drawer without fading away the frame layout.(in xml file or programatically)
I cant post pictures ( because of my low reputation number) but if it helps below is my xml file.
<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" >
<!-- Framelayout to display Fragments -->
<FrameLayout
android:id="#+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
<!-- Listview to display slider menu -->
<ListView
android:id="#+id/list_slidermenu"
android:layout_width="240dp"
android:layout_height="fill_parent"
android:layout_gravity="start"
android:background="#color/time_al_blue"
android:choiceMode="singleChoice"
android:listSelector="#drawable/list_selector"
android:paddingTop="15dp" />
</android.support.v4.widget.DrawerLayout>
That shadow is called the scrim color.
You want to make it transparent, so your content is not obscured, i.e.
mDrawerLayout.setScrimColor(Color.TRANSPARENT);
If you want to do that it would be best if you use Sliding Menu from Jeremy Feinstein
Here you can find an implementation of his library and if you like this solution you can use it to replace navigation drawer.

Combining NavigationDrawer and SlidingPaneLayout - SlidingPaneLayout from the right possible?

I'm using a NavigationDrawer as main menu in my app. Some of my fragments use the SlidingPaneLayout.
At the moment, I show the NavigationDrawer on the right and the SlidingPaneLayouton the left, always a little bit visible.
But I would like to have the NavigationDrawer on the left side and the SlidingPaneLayout on the right side (like in Hangouts) always a little bit visible.
Question:
I know how to get the NavigationDrawr to the other side, but I can't find out how (if possible) to move the SlidingPaneLayout to the right side? So that it slides in from the right...
my solution
<android.support.v4.widget.SlidingPaneLayout
android:id="#+id/sliding_pane_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/fragment_main_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="left"
android:layout_marginRight="0dp"
android:orientation="vertical" >
<include
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="#layout/card_toast_container" />
<FrameLayout
android:id="#+id/fragment_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<!-- marginLeft: set it to width - 150 in your code!!! -->
<FrameLayout
android:id="#+id/fragment_slider"
android:layout_width="150dp"
android:layout_height="match_parent"
android:layout_gravity="right"
android:layout_marginLeft="0dp" />
</android.support.v4.widget.SlidingPaneLayout>
and use some wrapping methods like for example following, for easier and more readable code:
public boolean isSliderMenuShown()
{
return !mSlidingLayout.isOpen();
}
public static void openSlider(boolean isSliderLeft, MySlidingPaneLayout slidingLayout)
{
slidingLayout.closePane();
}
public static void closeSlider(boolean isSliderLeft, MySlidingPaneLayout slidingLayout)
{
slidingLayout.openPane();
}
Set this to view inside navigation drawer:
android:layout_gravity="left"
you can try keeping it open in the start with:
SlidingPaneLayout sp = (SlidingPaneLayout) findViewById(R.id.spl);
sp.openPane();
Also keep your main content on the left and menu on the right
After my research and test, android.support.v4.widget.SlidingPaneLayout can't swipe out from right to left. The only effect is swiping out from left to right.
No matter whether android:layout_gravity= is start left end or right.
You can achieve that by adding the layout direction for you Slidingpanel layout
layout = (SlidingPaneLayout) findViewById(R.id.sliding_pane_layout);
layout.setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
before that make sure you have added a property android:supportsRtl="true" for your manifest file.
Step-1
In order to support RTL in your app, you first need to add android:supportsRtl="true" to the element in your manifest file.
Step-2
Add RTL support in SlidingPaneLayout
android:layoutDirection="rtl"
Step-3
Add LTR support in child views of SlidingPaneLayout
android:layoutDirection="ltr"
<SlidingPane
android:id="#+id/slidingPanelLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layoutDirection="rtl">
<include
layout="#layout/left_drawer"
android:layout_width="250dp"
android:layout_height="match_parent"
android:layoutDirection="ltr" />
<include
layout="#layout/view_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layoutDirection="ltr"
/>
</SlidingPane>
Note: add LTR support in both left_drawer.xml, view_container.xml

Categories

Resources