标签:
android:screenOrientation=
"landscape"
//横屏
android:screenOrientation=
"portrait"
//竖屏
// activity的 onCreate 函数中
this
.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR);
android:configChanges=
"orientation|screenSize"
(2)在对应的activity中,重载函数onConfigurationChanged
@Override
public
voidonConfigurationChanged(Configuration newConfig) {
super
.onConfigurationChanged(newConfig);
}
(1)创建一个类继承OrientationEventListener
public
class
MyOrientationDetector
extends
OrientationEventListener{
public
MyOrientationDetector( Context context ) {
super
(context );
}
@Override
public
void
onOrientationChanged(
int
orientation) {
Log.i(
"MyOrientationDetector "
,
"onOrientationChanged:"
+orientation);
}
}
if
(orientation == OrientationEventListener.ORIENTATION_UNKNOWN) {
return
;
//手机平放时,检测不到有效的角度
}
//只检测是否有四个角度的改变
if
( orientation >
350
|| orientation<
10
) {
//0度
orientation =
0
;
}
else
if
( orientation >
80
&&orientation <
100
) {
//90度
orientation=
90
;
}
else
if
( orientation >
170
&&orientation <
190
) {
//180度
orientation=
180
;
}
else
if
( orientation >
260
&&orientation <
280
) {
//270度
orientation=
270
;
}
else
{
return
;
}
Log.i(
"MyOrientationDetector "
,
"onOrientationChanged:"
+orientation);
关于屏幕旋转的处理,就说到这儿了
标签:
原文地址:http://my.oschina.net/wangxnn/blog/395260