最近项目中要求针对拍照功能添加横竖屏切换,具体需求如下
1.横竖屏加载不同的布局;
2.只处理0度横屏和90度竖屏,180度横屏和270度竖屏不做处理;
3.能通过系统的自动旋转开关控制横竖屏切换功能的开启关闭;
起初打算利用的系统的横竖屏切换功能来实现,具体操作如下
1.清单文件中配置 android:configChanges
<activity
android:name=".xxx"
android:configChanges="orientation|screenSize|keyboardHidden"
android:theme="@style/FullScreenTheme" />
2.重写 onConfigurationChanged() 方法
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
}
}</