|
这些代码都要放在Activity里。
横屏竖屏判断
方法1:
Configuration cf= this.getResources().getConfiguration();
int ori = cf.orientation ;
if(ori == cf.ORIENTATION_LANDSCAPE){
Log.v("HHHHHHHHHHHHHHHH", "HHHHHHHHHHHHHHHHHHHHHHH---heng ping ");
}else if(ori == cf.ORIENTATION_PORTRAIT){
Log.v("SSSSSSSSSSSSSSSS", "SSSSSSSSSSSSSSSSSSSSSSS---shu ping");
}
方法2:
DisplayMetrics dm = new DisplayMetrics();
mLauncher.getWindowManager().getDefaultDisplay().getMetrics(dm);
mWidth = dm.widthPixels;
mHeight = dm.heightPixels;
if (mHeight > mWidth){//layout port
// 竖屏 .......
}else{//layout land
// 横屏 .......
}
// 设置全屏
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
Display dis = getWindowManager().getDefaultDisplay();
screenWidth = dis.getWidth();// 获取屏幕宽度
screenHeight = dis.getHeight();// 获取屏幕高度 |
|