This question already has an answer here:
- Android Facebook style slide 25 answers
With the new facebook app it comes with an hidden sidebar that I would love to use something like that in my applications. It looks kinda like the sidebars that firefox mobile have...
Do you have any idea how to implement it besides re-implementing the ViewPager? I've tried with an HorizontalScrollView but that would also lead to re-implementation of it...
I'm not seeing any other way besides these two... any suggestions?
Thanks in advance
I did something like below:
Below is my code for something like facebook side menu bar
I did not use XML for the interface. I create everything in the below code. I think it should be easy to read and put into your eclipse.
I came up with a solution... I don't know if it is perfect but it is working well.
So what I did was a single FrameLayout with both of the Layouts stacked together and then I just animate the top layout to slide to the right of the screen (just need to call the slideTo or scrollBy. And basically it's that! Quite simple and effective! (the code though is not very pretty :P)
EDIT:
Some code samples.
This is the layout xml, quite simpe. The included .xml are simple LinearLayouts with a heading and a listview.
The "magic" happens in the animation:
The endOffset is the target movement. I set it before I start the animation, and the View I want to animate (in this case is the view with the id=news_list_parent) it is set on the constructor.
But just to understand how that works make a button and its listener would do something like this:
And finally override the back button to do the opposite of the button
Read this as pseudo-code =) This is what I did in the beginning, that code is lost :P
You can try out this. Good Example. Check for slider class..
https://github.com/gitgrimbo/android-sliding-menu-demo
I've created my own solution for this as well, as many stock solutions appeared to not work on older Android version or lacked proper instructions on how to get it to work.
My solution has the following features:
The solution uses a custom layout, called
SlidingMenuLayout
, that you are expected to add 2 views to. The first view you add is the menu, the second is the main view.The simplest way to add the layout to your existing project is to override your Activity's
setContentView()
method:In this example, MenuView is the view that will actually show the menu. It is up to you to implement this view.
Finally, you can add a button (typically in the top left corner of your main view), that calls
openMenu()
orcloseMenu()
on the layout as appropriate.The code for
SlidingMenuLayout
is found on the GitHub project page: