屏幕旋转

tech2023-07-08  107

unspecified,默认值,由系统决定,不同手机可能不一致landscape,强制横屏显示portrait,强制竖屏显behind,与前一个activity方向相同sensor,根据物理传感器方向转动,用户90度、180度、270度旋转手机方向,activity都更着变化sensorLandscape,横屏旋转,一般横屏游戏会这样设置sensorPortrait,竖屏旋转nosensor,旋转设备时候,界面不会跟着旋转。初始化界面方向由系统控制user,用户当前设置的方向 import android.content.Context; import android.content.pm.ActivityInfo; import android.os.Bundle; import android.provider.Settings; import android.view.OrientationEventListener; public class Base2Activity extends BaseActivity { private MyOrientoinListener myOrientoinListener; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /*myOrientoinListener = new MyOrientoinListener(this); boolean autoRotateOn = (android.provider.Settings.System.getInt(getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 0) == 1); //检查系统是否开启自动旋转 if (autoRotateOn) { myOrientoinListener.enable(); }*/ } @Override protected void onDestroy() { super.onDestroy(); //销毁时取消监听 /*myOrientoinListener.disable();*/ } /** * 重力旋转屏幕 * */ class MyOrientoinListener extends OrientationEventListener { public MyOrientoinListener(Context context) { super(context); } public MyOrientoinListener(Context context, int rate) { super(context, rate); } @Override public void onOrientationChanged(int orientation) { /* int screenOrientation = getResources().getConfiguration().orientation; if (((orientation >= 0) && (orientation < 45)) || (orientation > 315)) { //设置竖屏 if (screenOrientation != ActivityInfo.SCREEN_ORIENTATION_PORTRAIT && orientation != ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } } else if (orientation > 225 && orientation < 315) { //设置横屏 if (screenOrientation != ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } } else if (orientation > 45 && orientation < 135) {// 设置反向横屏 if (screenOrientation != ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE); } } else if (orientation > 135 && orientation < 225) { //反向竖屏 if (screenOrientation != ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT); } } */ } } /** * 强制横屏 * */ public void setRequestedOrientation(int requestedOrientation){ return; } }

 

android:configChanges="orientation|screenSize" android:screenOrientation="sensorLandscape"
最新回复(0)