在Android上禁用纵向模式

问题描述 投票:-3回答:2

我希望我的应用程序仅在横向方向上运行,因此我在清单中的每个活动中添加了android:screenOrientation="landscape"in。

但令人惊讶的是,我在Crashlytics中遇到了很多崩溃事件,而且数据显示当设备处于纵向模式时发生崩溃(它是如何进入按比例分配的模式)。

崩溃说

Caused by android.content.res.Resources$NotFoundException
Resource ID #0x7f0a001e
android.content.res.Resources.getValue (Resources.java:2327)
android.content.res.Resources.loadXmlResourceParser (Resources.java:3692)
android.content.res.Resources.getLayout (Resources.java:2143)
android.view.LayoutInflater.inflate (LayoutInflater.java:396)
android.view.LayoutInflater.inflate (LayoutInflater.java:354)
android.support.v7.app.AppCompatDelegateImplV9.setContentView (AppCompatDelegateImplV9.java:287)
android.support.v7.app.AppCompatActivity.setContentView (AppCompatActivity.java:139)
com.xx.xxx.Activity.onCreate (Activity.java:42)
android.app.Activity.performCreate (Activity.java:5447)
android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1094)
android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2393)
android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2493)
android.app.ActivityThread.handleRelaunchActivity (ActivityThread.java:4014)
android.app.ActivityThread.access$900 (ActivityThread.java:166)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1289)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loop (Looper.java:136)
android.app.ActivityThread.main (ActivityThread.java:5584)
java.lang.reflect.Method.invokeNative (Method.java)
java.lang.reflect.Method.invoke (Method.java:515)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1268)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1084)
dalvik.system.NativeStart.main (NativeStart.java)

这是我的onCreate方法@Override

   protected void onCreate(Bundle savedInstanceState) {
        setTheme(((AppTheme)getApplicationContext()).getCurrentTheme());
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_layout);
        ButterKnife.bind(this);
        presenter = new Presenter(this);
        setupPages();
        enterImmersiveMode();
    }

我想知道它是如何记录在Crashlytics上的,当设备处于纵向模式时发生崩溃。所以我猜,当它处于纵向模式时,它无法获得布局,因为布局文件夹中的所有布局都不在布局文件夹中。

android crashlytics landscape-portrait portrait
2个回答
1
投票

我不想鼓励懒惰。这是答案。

但是,请在下次使用Google。这是您可以轻松找到的一些基本信息。

android:screenOrientation="landscape"添加到清单中的活动。

    <activity android:name=".MainActivity"
        android:screenOrientation="landscape">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

0
投票

您还可以使用setRequestedOrientation(android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);更改运行时的方向,但您应该在setContentView之前调用

© www.soinside.com 2019 - 2024. All rights reserved.