Configuration类

Configuratation类是专门用于描述手机设备上的配置信息的类

得到对象的方法(activity中)

Configuration cfg = getResources().getConfigutation();

重点就是获取屏幕方向--

public int orientation   返回值:ORIENTATION_LANDSCAPE(横屏)、ORIENTATION_PORTSCAPE(竖屏);

String scteen = cfg.orientation == Configuration.ORIENTATION_LANDSCAPE ? "横屏" : "竖屏";

重写onConfigurationChanged(Configuration newConfig)来响应系统设置改变

横竖屏切换注意点:需要在manifest.xml中对应的activity中设置android:configChanges="orientation";

        并添加对应的权限:<uses-permission android:name="android.permission.CHANGE_CONFIGUTATION"/>

原文地址:https://www.cnblogs.com/liu666bin/p/2915383.html