I am writing an application that allows users to select various things on the screen.
On large 10 inch screens this looks best in landscape so I force landscape in the manifest file.
However, I want to make the application friendly for users of 8 (or 7) inch tablets as well. On these screen sizes the application should be forced in portrait mode.
Does anyone know how I can force the screen orientation depending on the screen size?
To find out if the device is a 7, 8 or 10 inches tablet, you can check this.
One way you can manipulate the device orientation is in every activity, after onCreate(), like this:
// set the orientation of the device
if(isTabletWith10Inches) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
} else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
Related
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_PORTRAIT);
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
I want to force two different orientations in my app. Only portrait for smartphones and only landscape for tablets. Since I must define it in the manifest for each activity, I can't figure out how to it programmatically!
I tried with setRequestedOrientation(int requestedOrientation) in my activity onCreate but it doesn't really start with my requested orientation. There is some dalay before my request orientation is set.
Develop two different versions each forcing it's own orientation and targeting specific screen sizes and distribute.
I am making an app in AIR mobile that I need to be in landscape mode all the time. On most devices this is OK, but on some devices (Motorola XOOM for example) the app launches in landscape. At least on the build in emulator that comes with Flash Builder 4.5. I don't know if this is a problem with the emulator or if the XOOM has different orientations than most devices.
Anyway, I want to make sure that the device is always in landscape mode. This can be checked easily:
if(stage.stageWidth<stage.stageHeight){
//rotate screen;
}
What do I need to put in if statement to make sure that it is properly oriented?
Thanks.
In the *-app.xml file you can define how application should act:
<aspectRatio>landscape</aspectRatio>
<autoOrients>true</autoOrients>
Even with aspectRatio set to landscape and autoOrients set to false in application.xml, sometimes a device's orientation is incorrectly set during the first frame of a mobile air 3.1 app, so stage.stageWidth will return the smaller of the two dimensions. Several frames later it will flip to the correct orientation. This could be what you witnessed.
So if you need to know the landscape stage dimensions when your app first loads, use:
var width :Number = Math.max(stage.stageWidth, stage.stageHeight);
var height :Number = Math.min(stage.stageWidth, stage.stageHeight);
You should not need to rotate your entire app manually, but here's how:
this.rotationX = 90
You should take care in locking rotation in your app, if you ever submit to the Apple store you can be denied if the app won't adjust to the device being held upside down. Many devices differ in what their 'default' orientation is, but setting your app descriptor with a starting aspect ratio of landscape should work. In AIR 3.3 there is a change so that setting stage.aspectRatio will keep the expected aspect ratio, regardless of the device's default orientation, or the device being upside down.
You need to set:
<aspectRatio>landscape</aspectRatio>
<autoOrients>true</autoOrients>
in your app descriptor. You also need to set
-swf-version=16
in your compiler options. With these setting and AIR 3.3, the app will hold a landscape aspect ratio, regardless if the device is rotated to the 'top' of the device is on the left or the right. Setting the aspect ratio to portrait will make the device keep portrait aspect ration, even if the device is held upside down.
In my apps I currently only support the portrait orientation for some activities, because I assume that most phone users will be using portrait orientation (and holding the device with one hand) most of the time.
On the new Honeycomb tablets, however, it seems likely that users will be using the landscape orientation much more often, so I'd like to support both orientations for more of my activities.
I'd rather not have to go back and add landscape layouts for the smaller screen sizes (all the way down to QVGA), though, so I'm wondering if there's a way of supporting landscape only for the xlarge screen type but not for the others.
You can combine the orientation and size attributes on the resource objects like:
res/layout/ -- default
res/layout-port/ -- portrait for any screen size
res/layout-xlarge/ -- any orientation on xlarge screens
res/layout-xlarge-land/ -- landscape on xlarge screens
Use the layout-port directory for your portrait-only layouts for smaller screen sizes, and then add your xlarge layouts to the layout-xlarge directory if you want to use the same layout file for portrait and landscape on xlarge, or to layout-xlarge-land and layout-xlarge-port if you want different layout files depending on the orientation.
Then, when you rotate to landscape on a smaller-screened device the OS will try to load a landscape layout but fail because there isn't one that matches and throw a Resources.NotFoundException. You can catch that exception, though, and force the activity to portrait mode in those cases using Activity.setRequestedOrientation():
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
setContentView(R.layout.titlescreen);
} catch (Resources.NotFoundException e) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
return;
}
[...]
}
That will then cause the activity to be recreated in portrait mode and it won't try to change again because using setRequestedOrientation() overrides the orientation sensor.