Overview
Some apps are designed for landscape only, for example a camera station on a tablet. Users still expect the picture to be the right way up however they place the device: with the buttons on the left or on the right.
KlugLayout sets the Android screen orientation to landscape on both sides. The app stays in landscape, but turns by 180 degrees with the device. It also reports the current display rotation, so an app can adapt its own content, such as a camera picture, to how the device is held.
KlugLayout is in daily use in the PetCam App on Android tablets, our proof of concept.
Features
- Landscape on both sides, turning with the device
- No switch to portrait
- Current display rotation: 0, 90, 180 or 270 degrees
- Active from the start of the app
- Does nothing on other platforms, so the code can stay in a cross-platform app
Supported platforms
Getting started
Add the extension to your application descriptor:
<extensions>
<extensionID>com.klug.layout</extensionID>
</extensions>
Apps targeting Android 16 should also allow a fixed orientation on large screens with this property inside <application> of the manifest additions:
<property android:name="android.window.PROPERTY_COMPAT_ALLOW_RESTRICTED_RESIZABILITY" android:value="true"/>
Quick example
import com.klug.layout.KlugLayout; stage.autoOrients = true; if ( KlugLayout.getInstance().isSupported ) KlugLayout.getInstance().setSensorLandscape(); // both landscape sides else stage.setAspectRatio( StageAspectRatio.LANDSCAPE ); var rotation:int = KlugLayout.getInstance().displayRotation;
API overview
| KlugLayout.getInstance() | Returns the single instance. |
| isSupported | True on Android. |
| setSensorLandscape() | Landscape on both sides, turning with the device. |
| displayRotation | The current display rotation in degrees (0, 90, 180, 270), or -1. |
Requirements
| AIR SDK | 51.x (HARMAN) |
| Android | Android 6.0 (API 23) or later |
| Permissions | None |