设定 ro.sf.hwrotation
在根目录下的init.rc文件添加 setprop ro.sf.hwrotation 270, 更改这个 property 为 270,强制屏幕旋转 270 度。
android2.2解决触控屏幕异常
$(android_root_path)/frameworks/base/services/java/com/android/server/InputDevice.java
添加包
import android.os.SystemProperties;
添加成员变量
private static final int HWROTATION = SystemProperties.getInt("ro.sf.hwrotation", 0) / 90;
在方法MotionEvent generateAbsMotion(InputDevice device, long curTime,
long curTimeNano, Display display, int orientation,
int metaState)中开始处添加
orientation = (orientation + HWROTATION) % 4;
android2.3.4 解决触控屏幕异常
$(android_root_path)/frameworks/base/libs/ui/InputReader.cpp文件中函数
TouchInputMapper::configureSurfaceLocked()中(注:此方法只是可行,
更优方案请深入android输入子系统) 原:
if (mAssociatedDisplayId >= 0) {
// Note: getDisplayInfo is non-reentrant so we can continue holding the lock.
if (! getPolicy()->getDisplayInfo(mAssociatedDisplayId, & width, & height, & orientation)) {
return false;
}
} else {
orientation = InputReaderPolicyInterface::ROTATION_0;
width = mRawAxes.x.getRange();
height = mRawAxes.y.getRange();
}
修改后:
if (mAssociatedDisplayId >= 0) {
// Note: getDisplayInfo is non-reentrant so we can continue holding the lock.
if (! getPolicy()->getDisplayInfo(mAssociatedDisplayId, & width, & height, & orientation)) {
return false;
}
char property[4]; int tmpInt;
if (property_get("ro.sf.hwrotation", property, NULL) > 0) {
switch (atoi(property)) {
case 90:
tmpInt=width;
width = height;
height = tmpInt;
orientation = (orientation + 1)%4;
break;
case 180:
orientation = (orientation + 2)%4;
break;
case 270:
tmpInt=width;
width = height;
height = tmpInt;
orientation = (orientation + 3)%4;
break;
}
}
} else {
orientation = InputReaderPolicyInterface::ROTATION_0;
width = mRawAxes.x.getRange();
height = mRawAxes.y.getRange();
}
记得添加头文件#include <cutils/properties.h>
reference:
http://cwhuang.info/2010/11/fix-rotated-screen-issues