We have implemented a facebook-like style menu to our app, which basically allows you to click a button and to slide the view over the side to access a menu hidden behind the top level view.
Currently, we have all of our views (this app has lots of screens) in separate XML files as any typical Android app. I should note we make heavy use of fragments.
The goal is to abstract the code out in such a way that instead of inflating our activities and fragments to the top level view, instead now we’d inflate it into this child of this top-level parent that would be a part of all of our activities (all of our activities subclass from a custom activity).
The way the menu.xml works is by having an outer FrameLayout that hosts a nested child FrameLayout that’s empty.
What we are trying to avoid doing is wrapping this outer menu code around every single one of our views XMLs, although this would certainly work.
I’m trying to find a programmatic way of having the menu code with the empty, nested FrameLayout in one file. Then when we go to inflate a Fragment’s or Activity’s XML, like so:
listView = (PullToRefreshListView) inflater.inflate(R.layout.pull_to_refresh_list_view, container, false);
instead of doing that, we’d inflate it into the nested child FrameLayout. Something like this is what I’m attempting:
listView = (PullToRefreshListView) inflater.inflate(R.layout.pull_to_refresh_list_view, container, false);
((FrameLayout) getActivity().findViewById(R.id.child)).addView(listView);
Currently this results in: “Unable to resume activity. No view found for id 0x7f090019 for fragment MyFragment[id= 0x7f090019]”
Any input is appreciated. Thank you!
What I did for a similar style menu was to add a frame layout and inflate a fragment into it. I then used a translateAnimation and layoutApp to translate the screen to the right place. I kept all this code in a slidingDrawerActivity which segmented the code nicely so that I could just call SlideOutMenu to use it
Hope this helps – if you want more deets just let me know
EDIT:
code for replacing frame layout with a fragment using support library