Requirement
I have an application with 2 activities, say A and B, with navigations like A->B
and B->A
(on back press). My requirement is
- I want a view/layout floating on screen, irrespective of which activity is currently visible. I inflate this view on app start(onCreate of activity A), it remains static on screen during the transition from A->B and when B is onscreen.
- So naturally this view should be inflated only once (when app starts, onCreate of A).
What I found out
I did some searching, and from what I could find, there are 2 methods to reuse layout in android
using
<include>
It just seems like a tool to write xml code of commonly used UI elements. It gets inflated every time it is used in a parent layout.
using
ViewStub
I did some research on using ViewStub and It also seems a way to reuse code segment in many layouts. It also need to be inflated every time we use it in a layout except it gets inflated only when we make them visible at run time.
Another hint of my requirement
For people familiar with iPhone development you can add view's to UIWindow
, which stays there irrespective of which UIViewController
is currently active. I want exact behavior in my application.
My original setup
I am targeting android 2.1 and above. It seems Fragment
is available from API level 11 (android 3.0) and above. One option is to use android compatibility library that enables usage of Fragment
in older versions. I am currently researching on that now. But I also would like to know if there is any other methods available to fulfill my requirement, rather than change my entire project and use fragments.
I have around 30 odd activities in my application and I want this layout floating over all of them. I just made out a test case with 2 activities to make the question simple and easy.
Activity A
do thatActivity B
doesn't and what doesActivity B
do thatActivity A
doesn't? Why not just have oneActivity
with your fixedView
and adjust everything else around it? – Nedry