android 转屏问题

1.在manifest.xml中添加
android:configChanges="orientation|keyboardHidden"
2.代码中重写
@Override
public void onConfigurationChanged(Configuration newConfig) {
// TODO Auto-generated method stub

if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
Log.d("screen", "PORTRAIT");
}
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
Log.d("screen", "LANDSCAPE");
}

super.onConfigurationChanged(newConfig);
}
3.改变时也可用
@Override
public void setRequestedOrientation(int requestedOrientation) {
// TODO Auto-generated method stub
super.setRequestedOrientation(requestedOrientation);
}

@Override
public int getRequestedOrientation() {
// TODO Auto-generated method stub
return super.getRequestedOrientation();
}
(1)this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);//不指定横竖屏
(2)this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);//指定竖屏显示

你可能感兴趣的:(android,xml)