android 屏幕方向

Activity的方向可以在AndroidManifest.xml文件里面去配置 android:screenOrientation;如果需要主动去设置方向可以调用setRequestedOrientation方法;当机身发生改变时屏幕的方向也会发生改变。试想这样一种情况,假如我要在只要屏幕发生改变时去执行一些操作,这个可能是AndroidManifest配置的,也有可能是Activity主动调用的,还有可能是机身变化引起的。有没有什么方法是只要屏幕方向发生改变就会去调用的?

在系统源码里面找了半天,在PhoneWindowManager.java发现了一个方法生气

 @Override
    public void setRotationLw(int rotation) {				
        mOrientationListener.setCurrentRotation(rotation);
    }

可以在这个方法里面去实现一些逻辑。

猜你喜欢

转载自blog.csdn.net/qq_32072451/article/details/80866845