Android: two previews of the layout for different devices - android

Hy,
I know I can launch my app on multiple devices at the same time but is there a way to view two previews of the layout for different devices at the same time without having to launch the avds?
Thanks

In Android studio 2.2 once you have opened your layout file, you can preview the layout for different devices like that :

Yes, there is a way.
Right-click on the activity_main.xml tab, and from the pop-up menu select split-vertically or split-horizontally.
This will create a second xml tab that can use a different screen for design/text. This can be repeated for more tabs, and the tabs can be "torn off" to float separately.

Related

Single Activity with multiple fragments

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

How Can I Create a Menu Of Three Buttons of Different Shape That Form a Menu in Android Studio

I want to be able to create a menu of three buttons like the one in this link in Android Studio
https://play.google.com/store/apps/details?id=com.easy.pedometer.step.counter.handle
The 3 buttons in the third screen is called TabLayout.
Here is link to the official documentation:
https://developer.android.com/reference/android/support/design/widget/TabLayout
Maybe, you find the ui a little bit different but you can customize.

Is there a quick and easy way to preview a layout at different screen sizes?

Is there a quick and easy way to see how my application will look on different screen sizes and shapes? Currently, I'm going into the AVD manager, editing my device definition, and then launching a fresh emulator. It takes maybe ten minutes for each one.
They layout is defined entirely from resource files. I don't actually need to execute the app. Is there a faster way to do this?
Edit: I should add: there are some custom widgets in the app.
While looking at a layout open the "Design" tab or open the "Preview" tab on the side. On the top of the window you will see a list where you can change the layout and orientation.
May not solve your entire issue, but it's a good to know.
If you want to have a preview of a static page (not rendered at runtime, like recyclerview), you could use android studio to do that.

tablet/handset layout structure with fragments

In this article http://developer.android.com/guide/practices/tablets-and-handsets.html
we use res/layout/main.xml with one fragment for handsets and res/layout-large/main.xml with two fragments for tablets. We must check if second fragment is in the layout to define if app runs on tablet or on phone.
I have 4 layout (2 for phone and 2 for tablet):
layout-port
layout-land
layout-sw600dp-port
layout-sw600dp-land
I check screen orientation to define if display is in portrait or landscape mode and check if layout contains a fragment to define if it is tablet or phone.
Is there any better way to work with layouts and fragments?
Is it possible to use one layout if we have two fragments for example http://i.stack.imgur.com/FtzKs.png and if a phone display doesn't fit both of them to show only the first one?
Thanks in advance! :)
What you're showing there is indeed possible! That is something called a Master Detail Flow (if you're developing in Eclipse with adt, check out he new activity wizard, which provides this as a template option).
This layout is basically just two fragments inside an activity (or, now, as of android 4.2, they can be nested in another fragment as well!) that interact with each other in a certain way. To create the layouts you linked to, one would detect whether the device is a phone or a tablet, and then set the visibility of the two fragments in different situations accordingly.
You will find a number of methods for detecting screen size here, whether you want to use screen size in inches, pixels, or the manufacturers' default categories.
And properties like visibility and sizing can be set programmatically using Layout Params and its various subclasses.
In any particular case, whether you choose to use multiple layouts to support different screen sizes or to do more of it programmatically is up to you. Personally, I think that it is always a good practice to design your code modularly and then use layouts to put all the pieces together (it'll save you a lot of headaches down the line if you decide you want to change things up). But either way, supporting more devices will always require more code, and there are no two ways around that...one of the curses of android development :P

How to display detail fragments side by side in tablet and vertical stack in mobile?

How to add multiple dynamic fragments in dual panel? I need to add Dual panel for Tablet and single pane for mobile. Also in Detail part having two fragments, if tablet it shows fragments side by side,else if mobile it shows fragments top and below.How to do this.
can i add another framelayout in dual panel? or In detail fragment,simply add linear layout?
Here's a link to android.com. There is quite a good tutorial how to support different layouts for tablets and smartphones. Basically you create to different layout folders (one for tablet, one for phone) and create the layout you want in them. Android will automatically select the right one.
http://developer.android.com/guide/practices/tablets-and-handsets.html

Categories

Resources