I used following code to prevent activity from starting again when phone is rotated..
android:configChanges="keyboardHidden|orientation"开发者_开发知识库
I used following format to get different views for horizontal and vertical displays...
For portrait mode xml in res/layout-port
, and For landscape xml in res/layout-land
The problem is these codes dont work together.....
Use this: Create two views with the same name. Move one in res/layout and different in res/layout-land and add this code in your activity.
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
setContentView(R.layout.main);
..
}
"main" layout is gotten from res/layout-land when phone is land oriented and other "main" is gotten from res/layout when portrait oriented.
Use this
android:configChanges="orientation|keyboardHidden"
instead of
android:configChanges="keyboardHidden|orientation"
then it will work.
精彩评论