【问题标题】:Disable portrait mode on Android在 Android 上禁用纵向模式
【发布时间】:2018-07-02 14:40:13
【问题描述】:

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

但令人惊讶的是,我在 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 上如何记录设备处于纵向模式时发生的崩溃。所以我猜当它处于纵向模式时,它无法获取布局,因为 (layout-land) 中的所有布局不在布局文件夹中。

【问题讨论】:

标签: android crashlytics landscape-portrait portrait


【解决方案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>

【讨论】:

  • 我正在做的不是懒惰。但是在发布我的应用后,我打开了 Crashlytics,当应用是纵向时发生了很多崩溃
  • 查看更新的问题,可能我上次没有解释清楚
  • 不..你之前没有解释过这些...就像...一样。
  • 我的错,可能我不知道怎么解释,你知道吗?
  • 发布你的整个崩溃
【解决方案2】:

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

【讨论】:

  • 它设置为横向并与我正常工作,但我遇到了很多崩溃。我不知道为什么!
  • 确实很奇怪。如果在 AndroidManifest.xml 中设置,即使用户旋转他/她的设备,它也不应该改变
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-03
  • 1970-01-01
  • 2012-11-04
  • 1970-01-01
  • 2017-09-06
相关资源
最近更新 更多