在继承了Activity的类中,可以通过重写onConfigurationChanged方法来判断屏幕的朝向
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
// 加入横屏要处理的代码
} else if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
// 加入竖屏要处理的代码
}
}
在Manifest.xml文件中注册Activity的信息:
< activity android:name="MyActivity"
android:configChanges="orientation|keyboardHidden">