Jetpack compose Two pane layout for landscape orientation? - android

How can I achieve two pane layout for Tablet Landscape orientation using Jetpack Compose?

Use Jetmagic. It was designed to create responsive apps using composable's in a way that is similar to how xml layouts are used under the older view system. Jetmagic handles all the device configuration changes that the older view system used such as orientation changes, screen size, screen density, language, etc. The demo app demonstrates orientation changes and shows two panes side-by-side where the left pane is a list and the right pane is the details. It's open source:
https://github.com/JohannBlake/Jetmagic

Related

Containers to hold screens in multi screen layout

On Android tablets, it looks like 2 different screens are being used for a Master/Detail-esque scenario in Jetpack Compose. Does anyone know what containers should be used for each screen? Considering that different screens would be used to replace the Detail pane/screen depending on the menu option chosen.

Android app displays correctly after device rotation but I haven't coded for it. How comes?

I've been searching docmentation and forums, and from all I've read so far, I conclude that in order to support portrait and landscapce modes, I need to code two identically named layout XML files, one in res/layout, the other in res/layout-land. Each layout places the widgets corresponding to the mode.
But what if there is no corresponding layout in res/layout-land (or if the later doesn't even exist)?
From a simple app containing a single text view in a ConstriantLayout, I see that the layout correctly adapts to the device orientation when run on my physical phone.
However, when run on a virtual device (Pixel 4 XL API 28, if that matters), the view is not changed when I click on the Rotate left or Rotate right buttons.
But, after clicking on the rotate button, a rotate icon appears at the bottom right of the virtual device. Clicking on that rotates the view.
Basically, my questions are:
Why is the layout correctly rotated on my physical device despite the fact that no landscape layout is present?
Why does the virtual device not rotate the layout when clicking on the rotate buttons, but offers me a rotation by displaying a temporary rotate icon?
A pointer to some documentaiton where all this is described in detail would be nice. It sure must be documented; I just haven't been able to find it.
Devices have a setting to enable or disable auto-rotation - on newer devices, when this is off, that rotate button appears which allows the user to choose to rotate (i.e., manually rotate).
As per the providing alternative resources, the most specific matching resource is used. So if you had a layout in layout-land, it will take precedence over that same resource in layout. (but wouldn't apply at all if you where in portrait mode as -land would disqualify that alternative resource).
That means that alternative resources are entirely optional - you'd only use them if your layout needs to be very different from one configuration to another. ConstraintLayout, for instance, uses relative positioning (i.e., position a view relative to the parent or to another view), which is often quite flexible to different orientations, screen sizes, etc. thus removing any need to need an entirely different landscape layout for a simple layout.

Which layout should be in landscape in android?

I have downloaded the google io application and I noticed that for landscape layout, its only the dashboard layout that have a landscape layout (in the layout-land folder).
My question is the following, is it for all the layout available in our project that we must create a landscape layout or it is only for the dashboard layout?
Thanks.
Kind Regards.
You are allowed to create a landscape layout for any layout in your app. You should do this when you want to have a different layout in portrait vs. landscape. Sounds to me like the Google IO app specifies a different landscape layout for only one screen (the home screen/dashboard), presumably because that's the only screen the developers felt needed a different landscape layout. Point is, it's up to you which screens have alternate layouts.
It depends on the data you have to show.
Sometimes there is more data which can be shown because of extra width in landscape and you have to compress data vertically in landscape. For such cases use different layouts

How to have no splitview in portrait mode in android?

I was able to create a split view using fragments in landscape mode to maximize the space. So for example, I can search on the left pane and it will show the detailed view on the right pane.
If the user switches to portrait mode during application usage, how can it be implemented in such a way that it is no longer in split view?
Android has this exact example in their code. You can specify a different layout dependent on the screen orientation. In the code you can perform a check to see what the current orientation is.

Best way to deal with different Android screen sizes?

We are writing an application for the T-Mobile MyTouch which is an Android based mobile phone. We have images that will be displayed on the default screen portrait mode (320 x 480).
Anticipating that the Android OS will be appearing on Netbooks with default landscape 16 : 9 screen format, what is the best way to handle images that are in a portrait mode format? In other words since you can't rotate the screen on these Netbooks, if you display a portrait mode image on landscape mode screen there will be large blank rectangles on either side of the image.
In terms of image resources within the application, such as is the case with background images, it is a common practice to have different image set for landscape and portrait mode, or even different screen sizes. Surely, you will adapt your layout to it, or at least have a good relative layout.
However, if you are wondering what to do when an image of an unknown size has to be drawn on the screen (e.g. in case of photo album application), it is fine to leave those black rectangles on both sides. Take a look at the behaviour of video player view on the Android Dev Phone 1. It will adapt the video frame height to landscape mode, and it will play the video in the landscape mode whether or not a portrait mode is more suitable.
You deal with it the same way you would deal with the user turning their phone sideways. This is as much a presentation decision as a UI one.
Remember Android supports using alternative layouts for identical Views. If you have a portrait layout e.g. res/layout/gallery.xml, you can create a landscape equivalent in res/layout-land/gallery.xml and Android will automatically load the latter layout file if the Activity is launched in landscape mode.
With the separate layout XML file, you can then arrange your image as you feel best fits the intent of your application (an application displaying medical images may well have different presentation priorities than one displaying a family portrait). You could for example just fill the background with a gradient, or more information that is otherwise hidden in portrait mode. It all depends on what you wish to achieve with your application and the lengths you are willing to go to to account for all possibilities.
But ultimately, provided the user can see the image in it's entirity without needing to flip their netbook on it's side, I imagine they'll be happy :)
You should design your screen with certain anchor points and then position the rest of the views in relation to those anchor points. For example if you have a screen layout which has a banner, a list of items and some buttons under the list then 2 of the ways these can be positioned on the screen:
Place banner at the top. Put the
list under it and then the buttons
under the list.
Place banner at
the top. Place the buttons at the
bottom of the screen and then the
list takes the space between the
banner and the buttons.
Layout 1) will have trouble with different screen sizes and the layout will look odd or may not appear correctly at all. Whereas, 2) gives you a better appearance for most screen sizes.

Categories

Resources