android:screenOrientation="landscape"横屏设置; android:screenOrientation="portrait"竖屏设置;
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); //横屏设置 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); //竖屏设置 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); //默认设置
<activity android:name=".Test" android:configChanges="orientation|keyboard"> </activity>
android:configChanges="keyboardHidden|orientation|screenSize"
public void onConfigurationChanged(Configuration newConfig) {
// TODO Auto-generated method stubsuper.onConfigurationChanged(newConfig);
if (newConfig.orientation==Configuration.ORIENTATION_LANDSCAPE){
// Nothing need to be done here
} else {
// Nothing need to be done here
}
}
private OrientationEventListener mOrientationListener; // screen orientation listener private boolean mScreenProtrait = true; private boolean mCurrentOrient = false;
abstract protected void OrientationChanged(int orientation); //screen orientation change event
private final void startOrientationChangeListener() {
mOrientationListener = new OrientationEventListener(this) {
@Override
public void onOrientationChanged(int rotation) {
if (((rotation >= 0) && (rotation <= 45)) || (rotation >= 315)||((rotation>=135)&&(rotation<=225))) {//portrait
mCurrentOrient = true;
if(mCurrentOrient!=mScreenProtrait)
{
mScreenProtrait = mCurrentOrient;
OrientationChanged(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
Log.d(TAG, "Screen orientation changed from Landscape to Portrait!");
}
}
else if (((rotation > 45) && (rotation < 135))||((rotation>225)&&(rotation<315))) {//landscape
mCurrentOrient = false;
if(mCurrentOrient!=mScreenProtrait)
{
mScreenProtrait = mCurrentOrient;
OrientationChanged(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
Log.d(TAG, "Screen orientation changed from Portrait to Landscape!");
}
}
}
};
mOrientationListener.enable();
}
startOrientationChangeListener();
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有