设为首页 加入收藏

TOP

Android4.0强制横屏竖屏
2014-11-24 11:47:43 来源: 作者: 【 】 浏览:1
Tags:Android4.0 强制

方法一:


android4.0/frameworks/base/services/java/com/android/server/wm/WindowManagerService.java
int computeForcedAppOrientationLocked() {
int req = getOrientationFromWindowsLocked();
if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
req = getOrientationFromAppTokensLocked();
}
// req = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; //强制横屏0度
// req = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; //强制竖屏左转90度
return req;
}


方法二:


android4.0/frameworks/base/services/surfaceflinger/SurfaceFlinger.cpp
void GraphicPlane::setDisplayHardware(DisplayHardware *hw)
{
mHw = hw;
// initialize the display orientation transform.
// it's a constant that should come from the display driver.
int displayOrientation = ISurfaceComposer::eOrientationDefault;
char property[PROPERTY_VALUE_MAX];
if (property_get("ro.sf.hwrotation", property, NULL) > 0) {
//displayOrientation
switch (atoi(property)) {
case 0:
displayOrientation = ISurfaceComposer::eOrientationDefault;
break;
case 90:
displayOrientation = ISurfaceComposer::eOrientation90;
break;
case 180:
displayOrientation = ISurfaceComposer::eOrientation180;
break;
case 270:
displayOrientation = ISurfaceComposer::eOrientation270;
break;
}
}
/* 强制旋转90度 */
displayOrientation = ISurfaceComposer::eOrientation90;
const float w = hw->getWidth();
const float h = hw->getHeight();
GraphicPlane::orientationToTransfrom(displayOrientation, w, h,
&mDisplayTransform);
}


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Android4.0隐藏状态栏电池图标 下一篇在Android上使用LocalSocket实现..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Linux 系统监控 的完 (2025-12-27 08:52:29)
·一口气总结,25 个 L (2025-12-27 08:52:27)
·【总结】100个最常用 (2025-12-27 08:52:22)
·有没有哪些高效的c++ (2025-12-27 08:20:57)
·Socket 编程时 Accep (2025-12-27 08:20:54)