本文主要是介绍android:angle=quot;90quot;,Android手机 G-sensor 倾斜度引出的开发问题,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
srclinuxandroidframeworksbasepolicysrccomandroidinternalpolicyImplWindowOrientationListener.java
private static final int MAX_TILT = 75; //手机的倾斜度阈值,改大则手机倾斜度(相对于水平面)很小屏幕就会旋转,改大手机倾斜度需要很大,屏幕才会旋转。
函数public void onSensorChanged(SensorEvent event) {
// Calculate the tilt angle.
// This is the angle between the up vector and the x-y plane (the plane of
// the screen) in a range of [-90, 90] degrees.
// -90 degrees: screen horizontal and facing the ground (overhead)
// 0 degrees: screen vertical
// 90 degrees: screen horizontal and facing the sky (on table)
final int tiltAngle = (int) Math.round(
Math.asin(z / magnitude) * RADIANS_TO_DEGREES);//计算手机倾斜的角度。
// If the tilt angle is too close to horizontal then we cannot determine
// the orientation angle of the screen.
if (Math.abs(tiltAngle) > MAX_TILT) { //如果采集到的手机倾斜角度大于android系统设定的默认值MAX_TILT 就不会上报
if (LOG) {
Slog.v(TAG, "Ignoring sensor data, tilt angle too high: "
+ "tiltAngle=" + tiltAngle);
}
clearPredictedRotationLocked();
}
参考坐标系:
这篇关于android:angle=quot;90quot;,Android手机 G-sensor 倾斜度引出的开发问题的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!