【问题标题】:I want my game to stay fixed on Portrait how can i do this?我希望我的游戏固定在纵向上,我该怎么做?
【发布时间】:2015-08-15 04:54:09
【问题描述】:

所以我想看看我的项目在风景中的样子,而且我肯定不喜欢这种外观。我想知道如何让我的项目保持纵向?我将不胜感激。

android.app.FragmentManager myFragment = getFragmentManager();
        FragmentTransaction fragmentTransaction = myFragment.beginTransaction();

        Configuration configInfo = getResources().getConfiguration();
        if(configInfo.orientation ==Configuration.ORIENTATION_LANDSCAPE){
            FragmentLandscape lScape = new FragmentLandscape();
            fragmentTransaction.replace(android.R.id.content,lScape);
        }else{

            FragmentPortrait lportrait = new FragmentPortrait();
            fragmentTransaction.replace(android.R.id.content,lportrait);
        }
        fragmentTransaction.commit();

【问题讨论】:

  • 看看this的回答。我相信你可以在清单中设置它。另外,开发者manifest docs
  • 谢谢。会看的。

标签: java android


【解决方案1】:

强制纵向模式有多种方法,但我首选的方法是在 AndroidManifest.xml 中为每个活动使用以下代码

android:screenOrientation="portrait"

稍后,如果您决定为平板电脑创建替代横向布局,您可以将 AndroidManifest.xml 中的相同行更改为:

android:screenOrientation="nosensor"

“nosensor”设置告诉您的应用使用设备的自然方向,并且在用户旋转设备时不会改变。因此,平板电脑将始终为您的应用使用横向,而手机将始终使用纵向。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-28
    • 1970-01-01
    • 2020-05-22
    • 1970-01-01
    相关资源
    最近更新 更多