设为首页 加入收藏

TOP

Android4.0强制横屏竖屏
2014-11-24 11:47:43 来源: 作者: 【 】 浏览:0
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实现..

评论

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

·请问c语言刚入门,该 (2025-12-26 10:21:04)
·python 编程怎么定义 (2025-12-26 10:21:01)
·09-指 针 (一)-c语言 (2025-12-26 10:20:58)
·About - Redis (2025-12-26 08:20:56)
·Redis: A Comprehens (2025-12-26 08:20:53)