React-Native Android定位

Saikat Saha:

我正在构建一个本机应用程序,我想在其中启用android平板电脑的(人像+风景)模式和android mobile的人像模式。

我知道iPad / iPhone的解决方案,所以如果有人可以帮助我进行android配置会很好

Saikat Saha:

请将以下代码添加到android / app / src / main / java / com / [您的项目名称] /MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (getResources().getBoolean(R.bool.portrait_only)) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }else{
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
    }
}

之后,创建三个bools.xml文件

android / app / src / main / res / values / bools.xml

<?xml version="1.0" encoding="utf-8"?>
    <resources>
        <bool name="portrait_only">true</bool>
    </resources>

android / app / src / main / res / values-sw600dp / bools.xml

<?xml version="1.0" encoding="utf-8"?>
    <resources>
        <bool name="portrait_only">false</bool>
    </resources>

android / app / src / main / res / values-xlarge / bools.xml

<?xml version="1.0" encoding="utf-8"?>
    <resources>
        <bool name="portrait_only">false</bool>
    </resources>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章