I am using Jeremy Feinstein's SlidingMenu library to implement a sliding menu on the right.
Is there any way to make the menu slide out without displacing/pushing the content view to the side? Currently, when the menu slides out, the content also gets pushed towards either the left or right (depending on which direction the menu is coming out from). I would like to make an implementation where the menu appears from either the left/right but "sits on top" of the content view (content view never moves, the menu view literally flies in and out).
Ive been digging about but there doesnt appear to be a simple function i can call to enable this. Do I have to implement it myself or am I missing something?
Time to answer my own question! :D
It seems that after looking through the source code of Jeremy Feinstein's SlidingMenu library, what happens is that the library actually "extracts" out our view and then somehow join it together with the sliding-out view. After that, the views are merely scrolled around (I could be mistaken, but i know the extraction of view does occur. As for the way the library accomplishes the scrolling and sliding, i didnt look into it too much.).
So, the answer to my own question is : No, it cannot be done by the library. No simple function available (due to the way the library achieves the sliding effect).
In the end, i opted to use a framelayout with overlapping views. One visible, the other invisible. Then i just change visibility and animate the views.
Related
I have a design for an app that will have a row of buttons below the action bar. Each button will open a different fragment. I am aware of ViewPagers, but I do not want the swipe between fragments functionality. I know that I can disable this functionality, but at that point is it worth using a ViewPager? I know this is a pretty common design paradigm, so how do most apps handle this sort of thing?
It seems like the ViewPager will provide some nice functionality out of the box, like switching between fragments and what not. So, I am leaning towards using one, but was hoping someone could provide some feedback on this approach.
Thanks!
Keep the buttons in the layout of your main activity. Have them call a function lets say loadFragment(Button button) on click.
This function then handles switching of the fragments, and you can change the display of the navigation buttons inside this function itself to highlight the appropriate button or something equivalent.
Google Design is always worth the reading.
Check http://developer.android.com/design/patterns/swipe-views.html for details.
Personally I have used ViewPager with tab layout for swiping purpose and it makes it easy to me to synchronise the transitions ( tabs and pages) where I put a red circle to the tab corresponding to the viewed page. With this approach I got a clean separated code.
The idea I'm having is having a view that can be pulled down on top of the current view, with similar animation features like the one you can pull down from the top all the time, on Android Devices.
Here's an illustration:
The idea is to grab it and being able to pull it down on top of the other view, and then being able to interact with that view. To slide it up again, you should grab the bottom of the view (the grey area in the illustration) again, and then pull it up.
I haven't even worked with animations before but I found a lot of topics on that, while searching for solutions to my problem, including this: Slide down view in android
but my impression is that, that is about making animations when the user isn't touching the phone.
What is the best way to do this?
Is there a better way to do something very similar?
EDIT:
Here's the topic that made me find the solution: How to make an Android SlidingDrawer slide out from the left?
And here's the solution I used:
SlidingDrawer Top-to-Bottom
You could use a SlidingDrawer, this is a built in component into Android, but as far as I know it slides only from bottom - up.
If you a comfortable to modify your app design, then this could be an option for you.
However, on internet are some libraries of custom SlidingDrawer that lets you put the marker on any side of your screen, so you can drag it top-down, left-right, right-left.. any way you want.
Useful links:
How to make an Android SlidingDrawer slide out from the left?
SlidingDrawer Top-to-Bottom
I am making an app that should implement a slider menu like the one in Spotify (where you slide the triangle in the middle to show the current playing song). The problem is I can't seem to figure out a decent method of doing this. I tried it with a Facebook like menu I found here.
However that just provides me with 2 linear layouts which are placed next to each other and are basically stretched or unstretched when expanding the menu. This gives some layout issues when expanding/collapsing (all items are placed below each other in the linearlayout when expanding and are quietly moved into the right place when collapsing the menu again).
In Spotify on the other hand it seems as if the layouts are on top of each other when the menu is expanded. This seems like a much cleaner way. However I have no idea on how to tackle this and Google doesn't really provide a lot of answers. Physically sliding the menu up isn't necessary, just getting the layouts on top of each other with some sliding animation on clicking the menu button.
Sorry for the long post, it seemed necessary to specify the question.
You dont need to re-invent a view or do anything fancy to get this functionality. Its called SlidingDrawer and is already available in the framework. Read this and this or watch this video.
I am looking to create a navigation or menu bar similar to the functionality of the one at the top of the Fox News app. I started to code this myself using a Gallery but I'm not sure how to hide the left and right arrows when they are not needed. I was also wandering if you would have to use images for the menu items or if you could just use TextView or buttons so I could change the text without having to modify an image. I have seen this type of navigation on several apps and I tried all types of searches trying to find code examples but I must not be using the correct name for this type of scrollable menu because I couldn't find anything. If anyone has an example or provide a link to an article I would greatly appreciate it.
Look into HorizontalScrollView. It is a Layout that will handle the smooth scrolling and is likely to be much less of a hassle to work with than Gallery for this operation (I just added one for a similar reason).
To handle the left/right, look into setOnTouchListener. I'm not sure if you can get the current scroll position without making a new child class of HorizontalScrollView to access protected methods. There may be other ways, however - I didn't need to add buttons so I didn't investigate.
I am trying to determine the "open" percentage of a SlidingDrawer in Android. It seems that the drawer only has onOpen, onClose and onScroll Listeners. OnScroll only provides methods for determining when scroll has ended and when scroll has begun.
TouchEvents won't work either because the SlidingDrawer can slide without being touched...
I tried grabbing the Animation of the SlidingDrawer using getAnimation() (and then somehow determining percentage based on that) but that returns null and so does getLayoutAnimation().
Any thoughts?
Very late answer, and I'm sure you don't care anymore, but someone else might. :)
I'm not entirely sure why you want a sliding drawer at all. It is likely easier and faster to write your own custom view that allows you to slide in and out, than to try to use sliding drawer. That way you will have way more control.
Another thought is to try getting the visible child rectangle of the sliding drawer from its container using getChildVisibleRect, and calculate the visible percentage using getWidth on the drawer. I'm not at all sure this will work. :)
Best of luck either way.