ideally i'd like my main activity to have 2 views rather than starting a new activity; currently i'm using a view switcher to switch from map view and list view.
on my map view i want a transparent action bar.
on the list view i want a solid one (so the list items aren't inaccessible under the action bar).
is this something that is possible?
or am i forced to create 2 seperate activities and pass a list of custom objects through a bundle to make the transition between views as simple as possible.
the final goal is to have a iPhone style flipper animation when switching the views so it's like you're viewing the current stats/details on the back of the map view.
apparently such a transition animation might not be possible between activities, but i'm still looking into it.....
You can use actionBar.show() and actionBar.hide() to toggle ActionBar feature.
Related
I'm trying to add a slidingUpPanel(Sliding up panel) across all activities. This panel consists of a viewpager which in turn consists of two fragments. One of these fragments has a recyclerView (more than 1000 items) and the other fragment has some data that changes dynamically depending on the users' choice. This panel is very similar to that of google play music and soundcloud. Now to display this panel I tested two approaches:
1) I created a base activity and added the sliding up panel to it and then extended rest of the activities to base activity. So this way I have to create only one panel and viewpager.
2) I included the sliding up panel in all activities. But this approach is quite unmanageable as I have create viewpagers for all activities and if data changes in one activity I have to write the code to reflect that change across all activities.
Now the problem with both the methods is that each time I open a new activity, a new instance of the viewpager and fragments is created. So, suppose if I have 1000+ items in the recyclerview fragment, switching activities takes more than 2-3 seconds, because each time new instance of fragment is created and the data is loaded all again. This will definitely result in bad user experience.
Is there any way by which the viewpager and the fragments are created only once(when the app starts) and are destroyed only when user closes the app? And data should not load each time user switches activities. I just want to reduce the activity switching time. Any ideas?
Thank you.
Well, for such ui elements as your sliding panel, which stays the same for many items it is preferable to have a single activity.
So if you have 1 activity, you can have a viewpager inside sliding panel, and that part stays untouched. Next, inside your activity you can have FrameLayout wich can be used to host fragments. Doing this you can achieve single instance of sliding panel and navigation between content with fragments.
Having some heavy data collections makes you wishing minimum recreation of that items.
Two approaches for this are (assuming you're using SlidingUpPanelLayout by sothree)
With bottom navigation view
Easy way to do it is creating a bottom navigation view and keeping it in MainActivity and attaching the sliding up panel layout to the bottom navigation view ( layout_above = bottomnavbar_id ) since bottom navigation stays throughout the app so sliding up panel will also have to stay with it
Without bottom navigation view
Create a frame layout inside MainActivity give attributes width and height as match_parent and create slidinguppanelayout and give attributes gravity="bottom"
make the frame layout stay above that slidinguppanellayout , use that frame_layout to show content your want to show from fragments
that's all
I have an Activity that holds some fragments.
This Activity is associated with a view pager, this view pager uses FragmentPagerAdapter, so every page of view pager is treated as a fragment.
Now, suppose I have customize the action bar view in any one of the fragment, and that custom view could be seen in other fragments also.
getActivity().getSupportActionBar().setCustomView(R.layout.custom_view_home);
getActivity().getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
This is because, we are customising the view, using the activity context.
My Question :
Q. Cant we set the Custom View of action bar within a fragment ? So, it would not get reflected to other fragment.
Short answer: Yes.
You should only allow currently visible fragment to add custom view to the ActionBar. Of course, you can do it right from the Fragment, with whichever context.
Requesting invalidation of the options menu will remove current custom view with the new one, i.e invalidating entire ActionBar. Similar approach you can use from the link above.
In my app, I need an ActionBar with a dropdown on it (a spinner / setNavigationMode NAVIGATION_MODE_LIST). The ActionBar needs to be visible in all the views/screens of the app, but the content underneath it changes - it's a list of items that when clicked, a detailed view of the item is seen.
The ActionBar state should be persistent throught the different views (e.g. the selected item in the drop down).
What would be the correct way to do it? I can think of:
A base activity that initializes the ActionBar by calling actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST), attaching an adapter if needed etc. (How to persist the dropdown state?)
Using fragments
Another way?
Which of these ways is preferred?
Thanks
I need to create an activity with an ActionBar, so that if you press the action bar buttons, the contents of the activity display the same information in different layout (one is a pie chart and the other a listview).
I don't want to use tabs or a viewpager, so what would be the best way to do this?
Build each view in a separate fragment, and use the actionbar buttons to set the current visible fragment.
Is there a way to use ActionBar tabs, but with the tabs switching ContentViews instead of fragments? The issue is that I have dual-pane layouts on large screens that have a fragment in each of two panes and I'd want to switch out the whole container view when that tab is selected.
Currently I'm using my own tabbing mechanism, but I'd like to integrate better into the built-in features and behavior of the ActionBar, and to save space by not having to have a separate ActionBar and tab bar when possible.
From the Action Bar docs --
To get started, your layout must include a ViewGroup in which you
place each Fragment associated with a tab. Be sure the ViewGroup has a
resource ID so you can reference it from your tab-swapping code.
Alternatively, if the tab content will fill the activity layout
(excluding the action bar), then your activity doesn't need a layout
at all (you don't even need to call setContentView()). Instead, you
can place each fragment in the default root ViewGroup, which you can
refer to with the android.R.id.content ID (you can see this ID used in
the sample code below, during fragment transactions).
If you specify a layout for your activity with slots for two fragments, you can replace them both (or even just one if that makes sense your app) in the ActionBar.TabListener callback. The callback still leaves you in control of the layout.