How do I rotate app content?
I already have a good understanding of t开发者_C百科he OrientationEventListener, and detecting screen orientation. But, how do I rotate or adjust the actual content (buttons, images, tabs, any objects)? Right now, when the user rotates the phone, the content doesn't move or rotate, and it appears sideways to the user.
NOTE: I am using the Droid 2 for testing, and I have noticed that if i I slide out the keyboard, the screen DOES rotate, which is kind of strange in my opinion.
Any help is greatly appreciated!
EDIT: Here is my code:
OrientationEventListener ole = new OrientationEventListener(this) {
@Override
public void onOrientationChanged(int arg0) {
TabHost ll = (TabHost) findViewById(android.R.id.tabhost);
try {
ll.forceLayout();
} catch (NullPointerException e) {
System.exit(0);
e.printStackTrace();
}
}
};
ole.enable();
Unfortunately, when the program reaches ll.forceLayout(), it throws a NullPointerException and causes the system to shut down.
SOLVED: I had to edit the manifest such that android:screenOrientation="sensor"
. Thanks for all your help!
but I have no idea of how to tell android to switch to the second view when the screen rotates
You don't have to tell it to. If you just create a layout-land folder in your project the system will know to pull layout files from that folder if the device goes in to landscape mode.
Try to call forceLayout () for your root view in the onOrientationChanged.
Just leave that android:screenOrientation="sensor" out of your manifest. It's the default.
精彩评论