We have an Android application made of menu of modules and each module has the same layout as on this picture:
You have a header with module name and two buttons on the bottom. The module itself is behind those three transparent elements. Left button allows the user to move to the previous screen and right button gets him back to the menu with modules. Text in header changes based on current screen action.
My question is how to build the module transparent frame. Is it possible to have one layout in Android on top of the other? Should we design the code as a parent class that would be inherited by all the modules? I am interested in some best practice. I have experience with Java but only theoretical knowledge of Android.
Prepare a separate common layout and use to add that layout to as many layouts you want.
for more details check this
What you are looking for are so called Fragments. These Fragments are sort of like Activities, with their own layouts and lifecycles, but you are able to use multiple Fragments at once. This means you'll be able to use one Fragment for your navigation and header, and one for the module behind it.
Related
I m new to Android development and stuck with design. I d like to design a single activity application with multiple fragments. But whatever I consider, I m stuck with design.
I first considered fragments as components or widgets that I could organize where I wanted on my screen. But a single activity has only one xml view layout and can not find a solution.
Here is what I want.
UI design
The problems are the following.
The layout choice: I need a layout for full screen fragment screen 1 but another splitted one for other screens.
The keyboard: if I do a fullscreen fragment layout for all my screens with a (game-keyboard) fragment and (dico-keyboard) fragment, how do I remove the keyboard in dico fragment on tablets ? And can I share keyboard code between both fragments ?
I saw that calling setContentView during runtime is kinda annoying as you have to reassign your variables and is not suitable.
All the applications I find are fullscreen single fragment on layout allowing libs like ViewPager. I can not find an example of composed screen with fragment components.
What layout would you chose, with what kind of fragments ?
Or do you know a library that allow composing fragments as widgets on screen ?
Thanks for your help.
Welcome to Android. Buckle up, it's going to be a bumpy ride.
First, you should spend some quality time with the Android Developer Guides.
Developer Guides | Android Developers
The insight for your particular challenge is that layouts are resources, and and you can have a layout resource that changes based on the configuration.
So for example, you could have a resource like layout_main with one XML file for small devices and a different XML file for large devices.
App resources overview | Android Developers
Create alternate layouts | Support different screen sizes | Android Developers
You can arrange fragments on a layout using the Android Studio layout designer.
You can add Fragments and navigate.
First of all yu need a navigation: In the left hand side on Android Studio you can find the Resource Manager Then click to Navigation then click to + and choose the Navigation resource file
After this you can add fragment to the navigation:
New Destination (green +) (Don't forget to give name to your fragments).
After this you can add the navigation to your activity's xml. You should use the app:menu=”#menu/bottom_nav_menu” code in your xml
Here a video about the process:
https://www.youtube.com/watch?v=Chso6xrJ6aU
I am learning Android Studio and I have recently come across listview.
I am making a project which has 6 buttons and each of those 6 buttons will open an activity where there are 2 additional buttons and if you click on 1 of those 2 activities you will reach the required page.The required pages have different text content.
I am approaching this problem by creating a new xml file for every activity however this leads to creation of many pages and I just wanted to know if there is any method which will reduce the number of files created for this project
If your two activity have similar look than you can use same layout,
else you have to create different layouts for all your activity.
If you have Activities that looks alike you can use the same layout file for both activities, and only change the behavior in the Java side.
And if you have activities thats acts alike you can also use the same activity and change the behavior depending on some extras.
I have an Android app with two classes:
-MainActivity
-SecondActivity
I have also two layouts for these classes (they are pretty similar).
I want to switch between these activities by 'shifting' to the right or to the left.
All materials I find are about switching by button.
Anyone would recommend using Fragments and ViewPager instead of Activity since you want sliding action and make use of the Android TabLayout.
Here is a tutorial that you can draw a basic idea from.
Could anyone give me a tip on how to build a layout like in the following picture?
The application i'm working on has absolutely nothing to do with VoIP but I'm trying to build something like this. One fixed toolbar at the bottom, an interchangeable middle pane with listviews, scrollviews or other, and another toolbar at the top which would change depending on the button selected on the bottom bar.
Also, would it be possible and good practice to keep all of this within a single activity?
You should NOT build an interface like this. Don't use bottom bars! Don't use labelled back buttons on action views!
You should read the Android design guidelines and then work with tab views... and other stuff referenced there and build an Android app.
Also, would it be possible and good practice to keep all of this within a single activity?
-Yes for sure, and yes with a slight catch, depending on what you mean.
One approach would be to create your top and bottom bars inside their own XML. Then in your activity onCreate() inflate and add at the top and bottom of your Layout.
If the bottom bar will not change ever, then you could actually add that into the layouts you already have. If you do it that way, to handle the listeners you could create an Activity that contains just the bottom bar click listeners and then extend that with all of your other activities.
Since the top bar can change though you'll probably have to inflate and add the views to that at run time, that way you can react to what is going on to add / remove / present the appropriate views in the top bar.
Also just because it is somewhat of a pet peeve of mine:
When designing your bottom bar please seriously consider the fact that some devices have soft buttons directly underneath the touch screen. And they are rather close to the screen on some devices. Applications with a bottom bar that is not tall enough create an opportunity for the user to hit one of the system buttons instead of one of the bottom bar buttons as they are intending (or vice versa). Which from a users perspective I must say is VERY aggravating.
Do not use bottom bars. To give a more familiar UI, put all of those functions into the top bar. Start by looking at the source code for the ActionBarCompat project in your android sdk sample folder.
The Android developer site is a good place to start. See
UI Guide
I also agree with the poster who recommended against this specific layout. It seems to have been developed for an iPhone and shouldn't be used "as is".
I have an Android app that I would like to convert to an Android library. The app is based around one activity whose entire XML layout contains only a webview that covers the entire screen. The library UI (really, just the webview) must now be integrated into the layout of other apps. For example, one parent app has a tab structure. I would like to have the library webview displayed in one of the tabs, with the tabs always visible at the bottom of the screen. Ordinarily, I'd opt to set the app-library boundary at the activity level but that does not work in this case -- we cannot pop up a new Activity from the library because that would cover all of the screen and the tabs at the bottom.
What is the best way to convert this to a library so that it works within the tab structure of the parent app? Where should the app-library boundary be? Some of my ideas are:
Let the library user create an activity with the custom layout that he prefers (tabs in this case). Make sure that the layout contains a webview. Use findViewById to get the webview object and pass this object into the library for the library to use to display pages. Main disadvantage here is that parts of the library need to hook up some Broadcast receivers onto the parent activity (which is not really part of the library in this scenario), and this coupling seems rather dubious.
Perhaps use fragments which were introduced in Android 3.0. However, these mostly seem geared towards tablets. Would these work in this case?
Is there another option compatible with Android 2.1+ that I am not aware of?
I decided to go with Fragments, using the compatibility library.
http://developer.android.com/guide/topics/fundamentals/fragments.html
http://developer.android.com/sdk/compatibility-library.html
Fragments are really the best choice in this case because:
They have a life cycle similar to that of activities, making conversion easy.
They are a chunk of UI with related functionality, which is exactly what's needed in this case.