共总结两种,有点区别,自己好好看吧
1, //获得当前的屏幕方向
public static int ScreenOrient(Activity activity){
//取得当前屏幕的方向,如果此值为-1表示androidManifest.xml没有设置Android:screanOrentation属性所以这样无法判断屏幕方向。
//可以使用另一种思路,即长度大于高度的为横屏,否则为竖屏。
int orientation = activity.getRequestedOrientation();//得到屏幕方向
int landscape = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;//横屏静态常量
int portrait = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;//竖屏常量
int width = activity.getWindowManager().getDefaultDisplay().getWidth();//得到系统显示属性后得到屏幕宽度
int height = activity.getWindowManager().getDefaultDisplay().getHeight();//得到屏幕高度
return width>height?portrait:landscape;//判断
}
![微笑](http://static.blog.csdn.net/xheditor/xheditor_emot/default/smile.gif)
2,
Configuration config = getResources().getConfiguration();
if (config.orientation == Configuration.ORIENTATION_LANDSCAPE){
//横屏,比如 480x320
System.out.println("横屏,比如 480x320");
isHv = Configuration.ORIENTATION_LANDSCAPE;
}else if(config.orientation == Configuration.ORIENTATION_PORTRAIT){
//竖屏 ,标准模式 320x480
System.out.println("竖屏 ,标准模式 320x480");
isHv = Configuration.ORIENTATION_PORTRAIT;
}