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);//指定竖屏显示

更多相关文章

  1. Android屏幕截图并保存截取屏幕的图片到指定文件
  2. android WARNING: Application does not specify ...
  3. TextView英文自动换行解决方法
  4. Android(安卓)中可重写的一些样式
  5. fullScreen时的软键盘监听(非重写Layout方式)
  6. Android(安卓)自定义View(API解析+Demo)
  7. 用ndk-build 工具手动生成编译android原生程序
  8. android 登陆、注册、并个指定用户充值
  9. [Android(安卓)L]关于Android(安卓)L的Service启动问题

随机推荐

  1. Spark RDD Python 学习笔记一
  2. 具有相同时区但不同的utcoffset()的Datetim
  3. 从子线程终止主线程
  4. Django -表单无效但没有错误
  5. 机器学习算法之七:5分钟上手SVM
  6. python安装mysql-python1.2.5
  7. 从“顶点小说”下载完整小说——python爬
  8. 自动完成在VS代码和Python中的自动化对象
  9. python基础学习第四天
  10. Python发邮件小工具