本文共 1241 字,大约阅读时间需要 4 分钟。
android:configChanges="keyboard|screenSize|orientation|layoutDirection"
application接下配置如下:public void HalfScreen(View view) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } public void FullScreen(View view) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); }@Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); Log.e(TAG, "onConfigurationChanged: "); //newConfig.orientation获得当前屏幕状态是横向或者竖向 //Configuration.ORIENTATION_PORTRAIT 表示竖向 //Configuration.ORIENTATION_LANDSCAPE 表示横屏 if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) { Toast.makeText(MainActivity.this, "现在是竖屏", Toast.LENGTH_SHORT).show(); setContentView(R.layout.activity_main);// 竖屏时显示的布局 } if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) { Toast.makeText(MainActivity.this, "现在是横屏", Toast.LENGTH_SHORT).show(); setContentView(R.layout.activity_main1);// 横屏时显示的布局 } }
转载地址:http://avjya.baihongyu.com/