Android Facebook style slide
Asked Answered
O

25

287

The new Facebook application and its navigation is so cool. I was just trying to see how it can be emulated in my application.

Anyone has a clue how it can be achieved?

enter image description here

On clicking the the top left button the page slide and the following screen is shown:

enter image description here

YouTube Video

Overmaster answered 28/12, 2011 at 15:39 Comment(5)
yes a video will also be helpful, to get to know the exact effect.Baty
@Baty here is the video: youtube.com/watch?v=ANLMaL7zn20Overmaster
@HarshaMV:- Try looking this thread.I think may help you somewhat.#8453820Mudcat
Very good article about slide-out navigation in Android - androiduipatterns.com/2012/06/…. Must read.Coster
I have implemented my own sliding menu, see here https://mcmap.net/q/87512/-how-did-google-manage-to-do-this-slide-actionbar-in-android-applicationExtort
C
176

I've had a play with this myself, and the best way I could find was to use a FrameLayout and lay a custom HorizontalScrollView (HSV) on top of the menu. Inside the HSV are your application Views, but there is a transparent View as the first child. This means, when the HSV has zero scroll offset, the menu will show through (and still be clickable surprisingly).

When the app starts up, we scroll the HSV to the offset of the first visible application View, and when we want to show the menu we scroll back to reveal the menu through the transparent View.

The code is here, and the bottom two buttons (called HorzScrollWithListMenu and HorzScrollWithImageMenu) in the Launch activity show the best menus I could come up with:

Android sliding menu demo

Screenshot from emulator (mid-scroll):

Screenshot from emulator (mid-scroll)

Screenshot from device (full-scroll). Note my icon is not as wide as the Facebook menu icon, so the menu view and 'app' view are not aligned.

Screenshot from device (full-scroll)

Chromophore answered 29/12, 2011 at 21:41 Comment(31)
Good application. However I found it particularly difficult to integrate to my app's code base (because the apps activities need to be loaded from an external activity). Anyway, just for my own curiosity, how much time did you need to write this library?Strafe
I'm not sure I understand. They are just normal activities and can be launched like any other, either as launch activities or through startActivity(new Intent(context, CLASSNAME)).Chromophore
@AmokraneChentir You can use different activities by calling getDrawingCache() in your non-menu activities and creating an ImageView from the bitmap. Then call startActivity(intent) & overridePendingTransition(0, 0) at the onClick method of the ClickListenerForScrolling class to immediately show the new activity and get the desired effect.Tertiary
Never mind guys. I have finally been able to integrate the menu with my project very easily :). Thanks again @PaulGrime!Strafe
@GoodGuyGreg could you, please, explain a bit more on how you suggest to call different activity from side menu; the steps involved?Vermiform
@AmokraneChentir could you post a skeleton code or explain about how you managed to achieve calling different activities?Vermiform
@gkr Ok, I will try to explain (through a Github gist) during lunch time.Strafe
@gkr I added an example for handling multiple activities here: github.com/mikodsantoss/android-sliding-menu-demoTertiary
@GoodGuyGreg thanks, I haven't got time to go through it. I'll comment more laterVermiform
I have a question regarding your answer: It is possible to have a button in the right top corner and scroll the above layout in the other direction (from right to left) ?Westley
I wonder if the custom HorizontalScrollView can use with ListView since the official document of HorizontalScrollView mentioned that it will force the ListView to display its entire items.Stratagem
@AmokraneChentir how did you open up different activities from the menu? can I have an example please?Glandulous
I am facing a problem, when I implement this code with my activity view are resize by navigation bar when navigation bar is expendedKeaton
i would like to to implement a option to drag the menu open beside the onclick (same as FB menu). Any tips how to do this?Klaus
How can we do the same thing vertically? I mean, Menu descends from the top , instead of coming from the rightSummerville
@GoodGuyGreg Your link seems like it would be helpful, but is no longer working.Quadri
Perhaps fragments is the only way to "switch out Activities"Quadri
this fork switches the activies without using fragments!Quadri
@PaulGrime I'm struggling with the width of the menu. How can I make it only as large as 1/3 of the screen width?Allaround
Thanks for your help, I was able to use the HorzScrollWithListMenu.java.Liking
Thank you very much @PaulGrime ...this is a great simple example and the most awesome thing is in this demo simple easy to understand and easily customize and there is no library project to use.Historic
@PaulGrime,Thank you very much Sir!Very easy to implement.Kress
This seems like a great implementation! Is it still a good idea to use it, or should one use the Navigation Drawer instead?Multiplicand
Hi Daniel. I'm not sure to be honest. I wrote this demo to see what was possible a couple of years ago. There might be (should be) better libraries for this by now I would imagine. I think one of the benefits of this approach is that it works for older versions of Android. But I'm not sure that's an issue in 2013 like it was in 2011.Chromophore
How current is this thread? Does Google's Android Official Navigation Drawer control provide all that is asked here? Is backwards compatibility offered?Credible
can you make the menu slides by move instead by button?Payne
This should be marked as the correct answer! , well explained :) +1Radiate
i am unable to put right sliding , when i added right icon and trying to sliding side .any idea , how to figure out . would you please add right side image, just like left side image and sliding left list .it will be great helpful.Beneficial
@PaulGrime Can you tell me how we can achieve this with drawerLayout so that it can work with both slide from left or click on button??Yeargain
Hi @RahulAbrol. Sorry, I wrote this years ago and haven't been involved in Android development since. I don't know how this could work with drawerLayout.Chromophore
@PaulGrime okey not a problem :)Yeargain
C
37

I've implemented facebook-like slideout navigation in this library project.

You can easy built it into your application, your UI and navigation. You will need to implement only one Activity and one Fragment, let library know about it - and library will provide all wanted animations and navigation.

Inside the repo you can find demo-project, with how to use the lib to implement facebook-like navigation. Here is short video with record of demo project.

Also this lib should be compatible this ActionBar pattern, because is based on Activities transactions and TranslateAnimations (not Fragments transactions and custom Views).

Right now, the most problem is to make it work well for application, which support both portrait and landscape mode. If you have any feedback, please provide it via github.

All the best,
Alex

Coster answered 19/3, 2012 at 10:24 Comment(9)
Hi, I just figured out that your approach is going to create a large screenshot bitmap every time you open the sidebar. It will grow the heap size and may cause out of memory error.Stratagem
Thanks dear korovyansk, Its very nice. but Absolute layout is deprecated in new OSs. Can you re code it again?Magisterial
Thanks everybody who gives feedback in github or here. I know about some bugs and have ideas how make the app better. I make it, when I will have free time.Coster
Hi koroyansk. I am using your library it work well. But I have a little problem. When slide bar list open I am starting the activity on listview item click.Activity start correct but slide-in animation does not work. Code ((MenuActivity) getActivity()).getSlideoutHelper().close(); startActivity(new Intent(getActivity(), MyActivity.class) .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP).putExtra("category", position));Liquate
in your case, new activity will open immediately without waiting of animation end, you can try to extend library and add callback for end of animation. may be I will add this feature to next version of library.Coster
can you make your apps icon on the action bar the button that slides the menu in and out?Chrysler
towpse, sorry I don't understand what you mean, can you rephrase?Coster
@korovyansk: Your library is easy to understand, and works good, but did you manage to get a callback for end of animation as u have said u will add this feature later, please let me know bcoz i want to call new activcities on list item click.Sabra
I recommend you to use this library github.com/jfeinstein10/SlidingMenu. My library was one of the first, but now SlidingMenu is much better. So I have no motivation in further development of my initial solution.Coster
A
24

Here is another lib and seems to be the best in my opinion. I did not write it..

UPDATE:

This code seems to work best for me and it moves the entire Actionbar similar to the G+ app.

How did Google manage to do this? Slide ActionBar in Android application

Ahouh answered 3/6, 2012 at 18:19 Comment(3)
I wrote this library, glad you like it. It's really basic for now, but I will be improving it over the coming weeks. More than welcome for other people to make changes to it as well.Godfree
This library is absolutely wonderful. It's so simple to use and works perfectly. Thank you. I'd just like to add that the sample only works with ICS (and Honeycomb I think) .. but the library works all the way back to 2.1, I'm using it no problems.Appurtenance
Not bad, it's pretty simple but works well and the setup is really quick. However, it's not very configurable from outside the library: all items have the same simple layout, and on the go there is no possibility of dynamic listing; both things would be easy to adapt but I really need grouping inside the list and that won't be that easy.Jerkin
S
22

I think facebook app is not written in native code (by native code I mean, using layouts in Android) but they have used webview for it and have used some javascript ui libraries like sencha. It can be easily achieved using sencha framework.

enter image description here

Sutherlan answered 29/12, 2011 at 5:13 Comment(4)
+1 The UI can changed without App Update, so it's definitely a web app and the android app is basically a web browser.Ere
I'm not sure this is necessarily the case. The skeleton for the UI can be native (e.g. the actual menu View and other native Views), and the content for those Views loaded dynamically. If the skeleton of the app changes, then an update would likely be required.Chromophore
I don't think that the facebook app is a webapp. Too fluent, quick. I know web/hybrid apps which look good "like native", but there's still a bit of lag compared to native. Not only the skeleton - the lists, map, etc. looks and feels native. At least with the current state of technology.Gilson
Ok, somebody told me that this app wasn't like this for about 2 months - so you're refering to an old version which I don't know. Anyways it might be informative to comment that the current app is definitely native.Gilson
L
20

Here is yet another (very nice) open source library!

The good feature about this one is that it is easily integrated with ActionBarSherlock.

Here's the github project link

Here's the Google Play download link

Loveridge answered 10/1, 2013 at 11:45 Comment(0)
O
17

I've just implemented similar view for my own project. You can check it here

Here is screen of sample application based on library I wrote: ActionsContentView Example

It is easy to use this custom view as element of XML layout. Here is example:

    <shared.ui.actionscontentview.ActionsContentView
      android:id="@+id/content"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      app:actions_layout="@layout/actions"
      app:content_layout="@layout/content" />

I you will have any questions about usage of ActionsContentView library I can write a small article at projects Wiki.

Some advantages of this library:

  • ability to slide view by touch
  • it is easy to adjust size of actions bar in XML
  • support of all Android SDK version starting from 2.0 and up

There is one limitation:

  • all horizontal scrolling views will not work at bounds of this view

Best regards, Steven

Ordure answered 16/7, 2012 at 0:11 Comment(4)
how to set frist UI is as your upload pic? i test it frist UI is webView on the screen. i hope listview is show when app is start. through your lib is 2.0,but your demo is 4.0,i hope you can also use 2.0.that is coolManzoni
@pengwang: I've just pushed some code to support this feature. You can do this while Activity.onResume() by calling viewActionsContentView.showActions();Ordure
Is it possible to disable touch events on hidden part ? For instance, when the right part is active then all views on the right are disabled.Hydroxyl
There is possibility to block content layout while action one is shown. I've emailed you a sample project.Ordure
P
16

With android support package revision 13( may 2013), there is DrawerLayout for creating a Navigation Drawer that can be pulled in from the edge of a window. And, navigation drawer is a design pattern now.

v4 support library

navigation drawer design pattern

Petree answered 15/5, 2013 at 20:41 Comment(3)
Yes, minimum API level supported is 4.Petree
And the compatibility library lets you use it on older devices. I just developed one for Gingerbread and later.Brahmani
This needs to be further at the top. Too many extraneous third-party libraries in the other answers.Chamblee
D
15

Did a roundup of an existing implementation and turned it into a library project plus example app. Also added XML parsing as well as autodetection of a possibly present actionbar, so it works with the native as well as a support action bar such as ActionBarSherlock.

This one also slides the action bar away!

The whole thing is a library project together with an example app and is described over at A sliding Menu for Android like google and facebook apps. Thanks to scirocco for the initial idea and code!

SlideMenu on Gingerbread SlideMenu on ICS with ActionBar

Dandrea answered 17/7, 2012 at 23:14 Comment(0)
D
10

This is simple and elegant: https://github.com/akotoe/android-slide-out-menu.git

Snapshot:

enter image description here

Danelle answered 2/1, 2013 at 6:17 Comment(4)
can you help me?? Question related to slider.. Here is the link #14501427Ardellaardelle
does it let you to slide by touching ? (mean swipe)Isochor
@Danelle I have been working with your sample, I think is great and easy to use but came to a problem, when rotating screen (I'm using android:configChanges="orientation" in the manifest with android 3.1 because I don't want the activity to be restarted) the screen rotates fine but the framelayout keeps its size and it doesn't look good, do you have a way around this? I have tried everything but can't fix it. thanksExpiry
@Danelle here is my question using your sample, please help me or give me some advice thanks. #16779411Expiry
M
10

I think that library does not mentioned:

jfeinstein10 / SlidingMenu

github url:https://github.com/jfeinstein10/SlidingMenu

  • works fine with action bar ActionBarSherlock which helps in backward compatibility!
  • Support right slide and not only slide via button!
Mayence answered 17/2, 2013 at 19:15 Comment(0)
C
8

Can't comment on the answer given by @Paul Grime yet, anyway I've submitted on his github project the fix for the flicker problem....

I'll post the fix here, maybe someone needs it. You just need to add two lines of code. The first one below the anim.setAnimationListener call:

anim.setFillAfter(true);

And the second one after app.layout() call:

app.clearAnimation();

Hope this helps :)

Couteau answered 20/4, 2012 at 19:26 Comment(0)
S
6

I've implemented this with AbsoluteLayout and a simple slide controller that moves the view to a negative offset to hide.

If anyone is interested, I can clean up the code/layout and post. I know AbsoluteLayout is deprecated, but it was a very straight forward implementation. Left View/ Right View, and when "sliding open", just move the left view out from a -X offset to the device's width - whatever you want to show of the Right View

Saransarangi answered 9/1, 2012 at 19:4 Comment(1)
I'll apreciate if you can do it without AbsoluteLayout! Thanks!Maremma
M
4

Hello this is best sample demo app which provides facebook like slide menu. Check the code here

enter image description here

enter image description here

Mitchellmitchem answered 11/4, 2013 at 6:12 Comment(0)
E
3

As a part of my Android Common Library (ACL) I implemented own SideBar. Main advantages:

  1. Side bar can be set to any position: left, top, bottom, right
  2. Both main view and sliding view are clickable
  3. Side bar can be partially shown
  4. Stylable attributes for SideBar make easier to change it's style
  5. Artifact in maven repo
  6. Part of a big library

Source code: https://github.com/serso/android-common/tree/master/views/src/main/java/org/solovyev/android/view/sidebar

Usage: https://github.com/serso/android-common/blob/master/samples/res/layout/acl_view_layout.xml

Extirpate answered 4/4, 2013 at 10:33 Comment(0)
O
3

Recently I have worked on my sliding menu implementation version. It uses popular J.Feinstein Android library SlidingMenu.

Please check the source code at GitHub:

https://github.com/baruckis/Android-SlidingMenuImplementation

Download app directly to the device to try:

https://play.google.com/store/apps/details?id=com.baruckis.SlidingMenuImplementation

Code should be self-explanatory because of comments. I hope it will be helpful! ;)

Ombudsman answered 18/5, 2013 at 23:3 Comment(0)
Q
3

I found a simplest way for it and its working. Use simple Navigation drawer and call drawer.setdrawerListner() and use mainView.setX() method in on drawerSlide method below or copy my code.

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"
android:background="#000000" >

<RelativeLayout
    android:id="@+id/content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff">

  <ImageView
      android:layout_width="40dp"
      android:layout_height="40dp"
      android:id="@+id/menu"
      android:layout_alignParentTop="true"
      android:layout_alignParentLeft="true"
      android:layout_marginTop="10dp"
      android:layout_marginLeft="10dp"
      android:src="@drawable/black_line"
      />
</RelativeLayout>


<RelativeLayout
    android:id="@+id/left_drawer"
    android:layout_width="200dp"
    android:background="#181D21"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    >
    </RelativeLayout>
 </android.support.v4.widget.DrawerLayout>

java file

   public class MainActivity extends AppCompatActivity {
DrawerLayout drawerLayout;
RelativeLayout mainView;
ImageView menu;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    menu=(ImageView)findViewById(R.id.menu);
    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mainView=(RelativeLayout)findViewById(R.id.content_frame);

    menu.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            drawerLayout.openDrawer(Gravity.LEFT);
        }
    });

    drawerLayout.setDrawerListener(new DrawerLayout.DrawerListener() {
        @Override
        public void onDrawerSlide(View drawerView, float slideOffset) {
            mainView.setX(slideOffset * 300);
        }

        @Override
        public void onDrawerOpened(View drawerView) {

        }

        @Override
        public void onDrawerClosed(View drawerView) {

        }

        @Override
        public void onDrawerStateChanged(int newState) {

        }
    });
 }
}

enter image description here

Thank You

Quiberon answered 11/4, 2016 at 13:1 Comment(0)
H
2

I'm going to make some bold guesses here...

I assume they have a layout that represents the menu that is not visible. When the menu button is tapped, they animate the layout/view on top to move out of the way, and simply enable the visibility of the menu layout. I have not thought about this causing any sort of z-index issues in the views, or how they control that.

Haemorrhage answered 28/12, 2011 at 16:34 Comment(3)
if you have used the app.. u can actually see that the layout slides to the right giving way to the menu section. i will try and make a video and upload it.Overmaster
I use the iPhone version, if the Android version is the same, then I doubt it's much different than what I described. I haven't written many animations on Android, so I couldn't tell you what the animation code looks like, but in rough words, I assume it's what I described.Haemorrhage
thank you, youtube.com/watch?v=ANLMaL7zn20 is it the same effect on iPhone.Overmaster
S
2

Android added the navigation drawer. Refer this

link

Seen answered 3/4, 2014 at 13:32 Comment(1)
And this one: developer.android.com/design/patterns/navigation-drawer.htmlHaphazardly
S
2

Here is the design and development guide found in official android documentation no need to add unofficial external library. Only android support library will do. Find the links here.

design and develop.

Saraisaraiya answered 26/5, 2014 at 12:16 Comment(0)
A
1

The Facebook Android app is possibly build with Fragments. The menu is one Fragment, the in-depth Activity (Newsfeed/Events/Friends etc) is the other Fragment. Basically a tablet 'master & detail' layout on a phone.

Alexisaley answered 28/3, 2012 at 10:15 Comment(1)
In this case we need to make actionbar inside fragment, so we cannot use any features of Android framework to build it, right? Actually I cannot be sure about facebook, but for many developers is too hard way to make actionbar without help of framework, I hope this time is already over.Coster
B
1

For info, as the compatibility library starts with 1.6 and this facebook app is also running on devices with Android 1.5, it could not be done with Fragments.

The way you could do it, is : Create a "base" activity BaseMenuActivity where you put all the logic for the onItemClickListener for your menu list and defines the 2 animation ("open" and "close"). At the end/beginning of the animations, you show/hide the layout of the BaseMenuActivity (lets call it menu_layout). The layout for this activity is simple, its only a list with items + a transparent part at the right of your list. This part will be clickable and its width will be the same width as your "move button". With that, you'll be able to click on this layout to start the animation to let the content_layout slide to the left and take the whole screen. For each option (i.e. item of the menu list), you create a "ContentActivity" which extends the BaseMenuActivity. Then when you click on an item of the list, you start your ItemSelectedContentActivity with the menu visible (which you'll close as soon as your activity starts). The layouts for each ContentActivity are FrameLayout and includes the and . You just need to move the content_layout and make the menu_layout visible when you want.

That's a way to do it, and I hope I've been clear enough.

Babbling answered 31/3, 2012 at 13:41 Comment(0)
N
1

I've been playing with this the past few days and I've come up with a solution that's quite straightforward in the end, and which works pre-Honeycomb. My solution was to animate the View I want to slide (FrameLayout for me) and to listen for the end of the animation (at which point to offset the View's left/right position). I've pasted my solution here: How to animate a View's translation

Nolen answered 3/7, 2012 at 15:5 Comment(0)
H
1

After a search for several hours, I found Paul Grime's solution probably is the best one. But it has too much functionality in it. So it may be hard to study for beginners. So I would like to provide my implementation which is came from Paul's idea but it is simpler and should be easy to read.

implementation of side menu bar by using java code without XML

Hydroxide answered 24/8, 2012 at 15:10 Comment(0)
E
1

I didn't see the amazing SimonVT/android-menudrawer mentioned anywhere in the above answers. So here's a link

https://github.com/SimonVT/android-menudrawer

Its super easy to use and you can put it on left, right, top or bottom. Very well documented with sample code and Apache 2.0 license.

Entrance answered 13/2, 2013 at 8:29 Comment(0)
S
0

In June 2012, Google has added "templates" in the Eclipse ADT plugin, and there is a template called "master/detail flow" which does exactly that (based on fragmets)

Surplusage answered 26/10, 2012 at 7:49 Comment(2)
Master/detail flow is not a sidebar menu in question. It is just two fragments displayed together (tablet) or separately (phone).Chorus
Well, in June 2013, Navigation Drawer Layout has been added, which is what more similar to need here, yet the ActionBar won't slide with drawer as Facebook style slider bar need here.Haphazardly

© 2022 - 2024 — McMap. All rights reserved.