转至http://blog.csdn.net/fulianwu/article/details/6864082
原本打算用layout-land写一个横屏xml文件用来自动切换,因为开发时用到了onConfigurationChanged这个属性,所以这个方法失效了,只能在onConfigur里动态操作了
if (Configuration.ORIENTATION_LANDSCAPE == this.getResources().getConfiguration().orientation)
{
WindowManager.LayoutParams params = getWindow().getAttributes();
params.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
getWindow().setAttributes(params);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
MainActivity.this.runOnUiThread(landscape);
}
else
{
WindowManager.LayoutParams params = getWindow().getAttributes();
params.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().setAttributes(params);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
MainActivity.this.runOnUiThread(initPlayHeight);}
在initPlayHeight和landscape方法加上横竖屏后需要的操作就可以了,runOnUiThread是为了保证在ui线程里进行操作,如果当前调用线程为ui线程,就立即执行,我是因为特殊原因才用了这个接口,大家可以直接写