Ons-split-view and ons-sliding-menu in the same app - android

I'd like to develop a mobile application that behave different in landscape and portrait mode.
In portrait (and or on small devices, like iPhone) I want to use the ons-sliding-menu component.
In landscape in big screens (eg: iPad in landscape) I would like to have the ons-split-view.
Is it possible to do that? How can I handle the two resolutions?
Thank you.

ons-split-view does exactly like that and it works on all devices, only depends on orientation as:
In portrait, it'll act as ons-sliding-menu, where you slide to show the menu.
In landscape, it'll be a split view

ons-split-view open/close function is deprecated and will be deleted from 1.2 version, try to use ons-if-orientation to switch between ons-split-view and ons-sliding-menu, that should be work, another option is to use ng-if.

Related

Different layouts for portrait and landscape modes based on screen width, not orientation per se

I have two versions of my layout, for smaller screens and for larger screens. Incidentally, I have a device where different layouts are required in different orientations. On other device that may not be so. I want to base it on screen width, not the orientation as such.
I've read this article and noticed that the "Available screen width" (w<N>dp modifier) can be used for specifying the proper layouts. It also says:
The system's corresponding value for the width changes when the screen's orientation switches between landscape and portrait to reflect the current actual width that's available for your UI.
Sounds perfect. So I put the smaller layout in the base layout folder, and the larger one into layout-w750dp. And the larger layout is picked. The problem is that it doesn't switch to the base layout when I rotate the device into portrait mode.
I have used the code from this answer to check the screen width in dp. It's 960 in landscape and 600 in portrait. Then I made sure android:configChanges="orientation" is not specified for this activity. I have also put Log into this activity's onCreate() - it is indeed called when I rotate the device, so it should have received the correct layout?.. Why doesn't it work and how to make it work?
Update: launching the activity (and even the whole application) in portrait mode right from the start still picks the w750dp layout.
Update 2: layout-land didn't work either. This layout is still picked in the portrait mode. Odd. It's becoming clear that the issue has little to do with width but with general functioning of the resource selectors.
Comments are getting long so to answer.
I just tested on tablet (768x1024 dp) two layouts first in layout, second in layout-w900dp and everything works just fine.
Second layout is shown in landscape mode which is correct because 900 < 1024.
Note: I used getResources().getConfiguration().screenWidthDp for screen width!
So it's definitely problem on your side :)
Ether you messed up your layouts or android studio messing with you :D.
Sorry for lack of more definitive answer :/

Seek for a better way to set different layouts for phone and tablet in landscape mode

In my android app, I want to load different layouts for phone and tablet in landscape mode, the layout in tablet landscape is the same as portrait in both.
So my layout folder in res is like layout(default), layout-land(for phone landscape), layout-sw600dp-land(for tablet landscape). But layout(default) and layout-sw600dp-land(for tablet landscape) is totally the same. I want to optimize this, any help is appreciated.
I plan to use layout alias, but I cannot understand the sample code in website, what I doubt is if I need to load the layout in the code, which xml file should I use?

Android Layout Folder for Devices/Tablets which are always in Landscape

I'm developing an android app for phones and tablets.
I want all of the devices to use portrait layout. I made a 'layout' folder for it. But, there are some X number of devices which are always in landscape mode. Probably, large tablets. So, I made a 'layout-land' folder too.
Which folder I need to add so that X amount devices will always display landscape layout only, while other devices will always display portrait layout?
Main requirement is to have only portrait layouts displayed. But, display Landscape layout when device itself is in landscape mode(default). I am talking about devices that display drawer in landscape mode, and the ones that open landscape layout of apps only.
Is this automatic?
I have android:screenOrientation="portrait" in manifest.
I can't test this as I don't have a tablet/large device.
I have already looked at this question and other similar questions.
Add the below line in your onCreate() method before setContentView()
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORT‌​RAIT);

Different WIDGET margins on different phones with android 4.0-4.2?

I've small problem - I've and app (home screen widget) for android ICS and higher. But different phones with different OS version (4.0.4, 4.1.2, 4.2, etc) and also different brands (Samsung, HTC, LG, ...) makes my app look diferent.
Ok, it doesn't happens always, but on some phones just Android adds automatic margins to my own - and on some not!!! How is this possible, and how to avoid this? Looks like every brand does it in their own way - which is fine for them, but bad for me :)
EDIT:
I use dp, not px. The main problem is not in dp/px nor in portrait/landscape changes. Main problem is, that for example on phone1 my widget has NO margins (it's like sticked to screen borders) and on other phones it has automatic margins like it should. When I add my own margin to widget provider, it has this margins on phone 1, but on other phones it has (my margins + automatic margins). Hope, now it's clear :)
Welcome to Reality show, when the Android it isn't platform independent, either Java it isn't.
For this reason a single android layout.xml should use elements which are doing layout acceptable in all targeted devices. The screen ratio differs, the dpi differs the resolution differs... As best practice:
use dp size instead of pixels
do different layout for portait and landscape case
have multiple folders based on screen size ( and different layout)
I hope it helps!
well, to close this answer - it looks like there is really no option to have same margin on all devices - as different devices uses different home screen implementation. I can't do anything with that...Closed.

How to handle size and position of controls in Android's Activity for portrait and landscape orientation?

I want to desing a GUI for android's tablet. By default i want to use landscape orientation of this application, so i placed the controls (text boxes, text views etc) accordingly, but when i change the orientation of tablet from landscape to portrait, whole GUI of activity gets distrubed. Can anybody guide/help me what is the best approach for designing of GUI in android such that controls appearance should remain correct in either orientation (portrait or landscape)? Thanks in advance.
You have to create another folder in the res directory called "layout-land". Put the layout file for landscape in this folder and the one for protrait mode in the normal "layout" folder. Both files must have the same name. Android will automatically chose the correct layout depending of the current orientation of the device.
Check the link below, it will provide all information about how to design an application to support multiple screens with different sizes and resolutions.
Supporting multiple screens

Categories

Resources