In an app I am working on, I'd like to have a bar with some controls always present at the bottom of the screen. It should overlay every activity in the app but also be able to disappear and reappear. To do this I've considered some options, such as simply using a linear layout and setting the visibility in every activity or using a fragment somehow. Probably those would work but I feel there must be a better solution. So my question is: what is the best way of doing this?
There are two ways you could do this. You could just use Fragments, and make your overlay be a fragment.
The other way would be to sublcass Activity with an AcitivityWithOverlay, which handles the overlay appearing and disappearing then have all of your activities inherit that. If I did it this way, I'd make my overlay a singleton so I wasn't creating extra versions all over the place that did the same thing.
Related
One activity in my app looks like below picture. In the below picture ,can any one suggest that best way to implement view,
view in my app
and when i click one of the options(filters in app) available on activity,
the view will be extended like below
view after one of the option selected
For this, i want to use a horizontal linear layout for below options bar,
when one of the options clicked, i wanna use slide up functionality and views show and hide functionalities.
can any one suggest better design for this . thanks.
I think for most apps, all toolbars should stay in the same place throughout the execution of the app. When the toolbar item ("Veg & Non Veg") is clicked, the filter should appear above the toolbar instead of below it. You can still use the slide up function, just have the toolbar layout displayed above (higher z-index) the filter linear layout.
You should also standardize the sizes for the distances/times to each location, personally I think the first one looks better.
Other than that, I think your UI looks pretty good!
I would like to ask you guys/girls, if somebody have any idea how i can achieve a two activity transition in honeycomb, where the the not used activity will be visible a quarter of the original size and the other activity will be place to the center. Also i need to mention i used activities smaller then the screen resolution with dialog theme to get them to the center.
I looked into the ViewAnimator, ViewSwitcher, ViewFlipper, but i`m not sure if can do that. (Sure need to override this classes)
Somebody have any idea ?
You cannot have two activities "active" at the same time so showing any proportion of one activity and another and interacting with both is not possible, if you don't care about interacting with both simultaneously you might look at the SlidingDrawer class, a lot of people have customized that.
It is possible to kind of fake what you are asking by using two layouts and changing their proportions/position at runtime, for instance you could have a layout that takes up the entire screen, then on some event it could be re-positioned/sized and a hidden layout shown.
That is if I am understanding your question correctly.
Update
Also have you looked at fragments?
Im making a music player/library app in wich I would like a frame/toolbar on top of all other activities as a header. This frame/toolbar will show information about the current playing track and have some controlls like play, next and stop etc. and be a separate selfsufficiennt activity. Is this possible and if so, how?
You can create an ActivityGroup. This is how TabHost is implemented. So your ActivityGroup would fill the whole window and implement the toolbar. Then you could swap out Activities in the bottom part.
Currently I don't think that making a static top bar it's own activity in the life-cycle idea. However, what you can do is have every activity have the top bar and just re-create the bindings needed for each activity. It gives the idea that a section is static.
Now this breaks down if you start doing animations between the screens. Another solution is to just have a single activity and swap out the views. This allows for animations between screens be custom and only the parts that change need to create the connections they need. The trade off there is that you'll lose any kind of state saving and history that you gain by using an activity orientated approach.
I think you can do something like this on Honeycomb tablets as the fragments idea could be implemented like that but I've never explored it much.
I've recently started developing Android Apps, and whilst the model is making more sense the more I look at it, I cannot do something (nor find any reference material on it) which to me seems quite simple.
I have an activity which has five buttons along the bottom, and a blank View taking up the rest of the screen. I want, upon clicking these buttons, for an activity to be opened in (and confined to) this view. I can get a new activity running without incident, but this opens in a new screen.
If anyone can show me an easy way to launch a (sub/child?) activity within a view which is defined in the parent activity's layout xml file - equally, it could be created in the parent activity - you'd really be doing me a favor!
I'd recommend taking a look at TabHost. The tabhost is an Activity itself, and the sub-views are all Actvities as well.
Here is a good tutorial that'll get you going very quickly. There is a more work to create (optional) icons for the tabs (also describe in the tutorial).
Hope this helps.
Edit* You mentioned buttons being at the bottom of the screen. Take a look at this SO Question
You can achieve that by using an ActivityGroup... here is a simple example which shows how to do it using a TabActivity:
http://web.archive.org/web/20100816175634/http://blog.henriklarsentoft.com/2010/07/android-tabactivity-nested-activities/
Of course, you will have to change the code since you are not using TabActivities. Just take a look at the getLocalActivityManager and getDecorView methods that is what you will be using.
Sorry, I know that this topic has been covered a bit. I've read the related posts and am still a bit confused. I am working on an app that while the prototype will have 3 main screens, it will eventually have dozens. Each screen will present either dynmically changing status or take user input. To visualize, it is required to be laid out similar to how MS Word or a typical PC is. It has a status bar at the top and a navigation bar at the bottom that is common to all screens (slight tweaks for some screens, like different icons) in the middle is what I would call a view pane that needs to be updated with a applicable layout.
The status, nav bar, and each screen are defined in their own layout xml file. For my first swag at it I just used a ViewFlipper and loaded the 3 screen layouts into it. However that means that currently I have one main Activity which will not be maintainable as I continue to add screens.
It feels right to me that each screen layout should have an associated Activity class that understands how to control that screen. I need to figure out how to load that into the center pane dynamically. However I thought I read in another post that using multiple Activities can be a CPU and RAM drain.
Currently I tried making one of the screens it's own Activity and kick that off from the main Activity by creating an Intent and than calling startActivity. However that causes the new screen Activity to reside on top of the main Activity. The interesting thing is that then pressing the back button dismissed that activity and returns me to the main.
So far I haven't figured out how to setup having a different Activity control what happens in the center pane.
If I continue down the multiple Activity path, should my main Activity be inheriting from ActivityGroup?
Are using View classes more applicable in this case?
I know this has been a long post. I'd appreciate any advice.
Thanks!
CB
As you noticed, Android will implicitly track a stack of started activities in a task, and the 'back' button ends the top one, reactivating the next one down. I would advise you to think about which kinds of things the user might expect the back button to do, and make it so that activities are separated along those lines.
I haven't played with ActivityGroup so I can't advise you there. If you go with completely separate activities, you can have them all use the same "shell" content view with the common nav/status bar. Have a superclass or utility class handle populating and managing that from there. Then use a a LayoutInflater (you can call getLayoutInflater()) to fill in the middle with your Activity-specific view.
If you want one of the activities to have multiple screens, you might still end up with a ViewFlipper in the center slot. Again, you want to have an Activity transition wherever you want the user to be able to go "back"; that also means you may NOT want to have a change of activities in cases where screens are closely related or part of the same logical thing-being-done. (You can override the back button's behavior, but unless you have a good reason to, it's best to just arrange the app so that Android's basic setup helps your app's UI rather than working at cross purposes.)
If you want to use activities in the fashion you talked about, you might look into using a tab activity. It actually works in the way you want, you just need to hide the tab widget and put your navigation bar there instead. Or, you could go a little deeper and make you own similar tab-like ActivityGroup like Walter mentioned if you have more time.
You could use a view pager with fragments to accomplish the flip between the different views but still allow your activity to have full control over it. The activity can control the menus while the fragment controls your viewing area. This way your back button will properly dismiss the activity containing all pages related to the activity instead of walking down the stack.