android 横竖屏判断
1、在AndroidManifest.xml文件的activity中配置 android:screenOrientation="portrait";竖屏显示(高比宽要长) android:screenOrientation="landscape":横屏显示(宽比高要长) 2、获取屏幕宽高度判断 Point point =new Point(); /*int width=getWindowManager().getDefaultDisplay().getWidth(); int height=getWindowManager().getDefaultDisplay().getHeight();*/ getWindowManager().getDefaultDisplay().getSize(point); int width=point.x; int height=point.y; /*DisplayMetrics metrics =getResources().getDisplayMetrics(); int width = metrics.widthPixels; int height = metrics.heightPixels;*/ //竖屏 if(width<height){ //横屏ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE //竖屏ActivityInfo.SCREEN_ORIENTATION_PORTRAIT //设置成横屏 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } 3、在activity中重写onConfigurationChanged方法 public void onConfigurationChanged(Configuration newConfig) { if(newConfig.orientation==getResources().getConfiguration().orientation){ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } //setRequestedOrientation(requestedOrientation) }