Change NativeScript XML layout based on orientation - android

I have a question about NativeScript orientation (Landscape and Portrait).
Is it possible to check if the device orientation is landscape or portrait and based on that switch the XML layout file? For instance, use lay.land.xml for landscape and lay.port.xml for portrait.
Thank's for all...

NativeScript already does this out of the box. Name your files <file-name>[.<qualifier>]*.<extension>
land - orientation is in landscape mode
port - orientation is in portrait mode
Note: All qualifiers are taken into account when the page is loading. However, changing the device orientation will not trigger page reload and will not change the current page.
This is documented here: https://docs.nativescript.org/core-concepts/navigation#orientation-qualifiers

Related

UI is not changing as expected while changing orientation in android

Here I am using different UX designs for portrait and landscape mode for a particlular activity. Created the folders layout-sw600dp and layout-sw600dp-land ,layout-sw720dp and layout-sw720dp-land for portrait and landscape mode. But the corresponding UX is not displayed while changing the mode. That is it loads the launching mode's expanded version while rotating the device. This means it will show the expanded version of landscape design while changing that to portrait. Tried the below code in the manifest. But no hope.
android:configChanges="keyboardHidden|orientation|screenSize"

Landscape include layout in Portrait orientation

I'm currently developing an app that will show a physical representation of an ID card, i have this view as an XML file on both landscape and portrait mode.
My question is: is it possible to have the phone in Portrait mode and use only this layout as an include in landscape mode? The goal is to have a nice elegant ID Card shown on the screen like the picture here. Thank you.
Edit: so in other words I need to use a LANDSCAPE resource while being on PORTRAIT mode.
You can add android:screenOrientation="portrait" to your Activity in the manifest and this will lock the Activity in portrait mode.

Multi-windows in Android 7.0 - Always get landscape layout even though device in multiwindows portrait mode

I am developing an android application that supports multi-windows feature on Android 7.0.
I followed this guide on https://developer.android.com.
, imported sample project https://github.com/googlesamples/android-MultiWindowPlayground
I create a new resource named layout-land and did some testing. I recognized that landscape layout is inflated even though the device is in portrait mode.
Check out attached images.
How can I set portrait layout when device is in portrait mode.
Assume you have two screens. One is in landscape and one in portrait.
How can you say which one is in landscape and which one in portrait?
In portrait width of the screen is less than height.
And for landscape width of the screen is greater than height.
Agree?
So, here, when you enter multiwindow mode your app's window no longer fits screen - width is greater than height and it is considered as landscape.
That is why landscape layout resource is used.
There is no separate modifier for layout resource to be used in split-screen mode.
The only thing you can do to achieve portrait in your case is to remove layout-land.
Or you can create two separate layouts (without any modifiers such as -land) and in activity call activity.isInMultiWindowMode(); to choose corresponding layout you want to use.

REVERSE_PORTRAIT is not detectable?

I am developing an App, and I want whenever the user change the orientation of the device I display the current orientation of the device. Actually, I achieved this step, but when i rotate the device to be in REVERSE_PORTRAIT the screen does not obey the rotation, in other words, my screen can not be in the REVERSE_PORTRAIT.
In the manifest file, I changed the value of android:ScreenOrientation to be user, but still in the same problem, all the three orientations PORTRAIT, LANDSCAPE and REVERSE_LANDSCAPE are detectable EXCEPT REVERSE_PORTRAIT
How can I find a solution for this problem?
You can try to use fullSensor if you want every possible orientation
"fullSensor" The orientation is determined by the device orientation sensor for any of the 4 orientations. This is similar to "sensor" except this allows any of the 4 possible screen orientations, regardless of what the device will normally do (for example, some devices won't normally use reverse portrait or reverse landscape, but this enables those). Added in API level 9.
all the possible values for screenOrientation and some explanations are here :
http://developer.android.com/guide/topics/manifest/activity-element.html

how to get landscape view when i changed portrait to land scape?

I have implemented an application for android 7 incs tablet.In my application i have used two types of layouts in layout-land and layout-port directories with same xml name and different designing.
In this application the tablet view is in landscape mode as by default when i change the orientation of emulator the the view is calling portrait xml from layout-port and if again change emulator orientation it is not getting xml view from layout-land.
I have implemented my application as follows:
if(wm.getDefaultDisplay().getOrientation()==1){
//portrait view code
}
else{
//landscape view code
}
from the above logic i can get the view from land scape to portrait but i can't get same view portrait to landscape.
How can i get my land scape view when i change landscape to portrait to landscape?
please any body help me?
That seems to be a problem with the emulator. You don't have to implement from code the orientation changes, since the system have by default this behavior. Just place your xml files in layout-land and layout-port and on a real device it will work fine.
The bug has been reported and you can see this here
You can use this code:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
or
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
You maybe also have to set this in your manifest under activity:
android:configChanges = "orientation"

Categories

Resources