Rotational Forces, Part Five

In past posts in the Rotational Forces series, we have seen how to have your activity react to screen rotations, as well as how to force your activity to remain in one orientation (e.g., portrait).

However, we haven’t covered the iPhone Scenario.

You may have seen one (or several) commercials for the iPhone, showing how the screen rotates just by turning the device. By default, you do not get this behavior with the T-Mobile G1 — instead, the screen rotates based on whether the keyboard is open or closed.

However, it is very easy for you to change this behavior, so your screen will rotate based on the position of the phone: just add android:screenOrientation=”sensor” to your AndroidManifest.xml file:

[sourcecode language=”xml”]
package="com.commonsware.android.rotation.five"
android:versionCode="1"
android:versionName="1.0.0">

android:screenOrientation="sensor"
android:label="@string/app_name">







[/sourcecode]

The “sensor”, in this case, tells Android you want the accelerometers to control the screen orientation, so the physical shift in the device orientation controls the screen orientation.

At least on the G1, this appears to only work when going from the traditional upright portrait position to the traditional landscape position — rotating 90 degrees counter-clockwise. Rotating the device 90 degrees clockwise results in no change in the screen.

Also note that this setting disables having the keyboard trigger a rotation event. Leaving the device in the portrait position, if you slide out the keyboard, in a “normal” Android activity, the screen will rotate; in a android:screenOrientation=”sensor” activity, the screen will not rotate.

About author

AndroidGuys
AndroidGuys 4641 posts

Founded on November 5, 2007, we've enjoyed bringing you the latest in Android news and rumors. Updated daily, we strive to deliver reviews, opinions, and updates on all things related to Android.

You might also like

News and Rumors

Q3 2010 Quarterly Report Card (US Carriers)

We put this feature together to help fill you, dear reader, in on we think each of the big four wireless providers are doing as it pertains to Android. Using the same system as the first time around, we conducted a blind, internal poll with members of our staff deciding how they would grade each U.S. wireless provider on their job. You know, like a teacher handing out grades. How did your provider do?

Featured

HTC DLX may get a much wider release

New information and images surfacing over the last few days suggest HTC will be deploying the rumored “DLX” smartphone to a wider audience this fall. According to reports, the 5-inch

News and Rumors

New Samsung Galaxy trademarks hint at upcoming device names

Our interest is piqued with names like Galaxy Thunder, Galaxy Accelerate, and Galaxy Express.