我的 android 应用程序没有旋转问题可能出在哪里?

问题描述

旋转似乎在我的应用中不起作用。我找不到问题出在哪里。如果有人可以帮忙。起初它可以工作,但后来我不知道代码中有什么改变使它停止旋转。如果除 android manifest 以外的任何类可能包含错误,请告诉我以便上传,谢谢。

这是我的 AndroidManifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.how">
<!--
     The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
     Google Maps Android API v2,but you must specify either coarse or fine
     location permissions for the "MyLocation" functionality.
-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher_foreground"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_foreground"
    android:supportsRtl="true"
    android:theme="@style/Theme.HOW">
    
    <activity android:name=".UploadID"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.UploadID"/>
    <activity android:name=".Register" />
    <activity android:name=".Login" />
    <activity android:name=".SplashScreen">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

    <meta-data
        android:name="preloaded_fonts"
        android:resource="@array/preloaded_fonts" />
    <provider
        android:authorities="com.example.how.fileprovider"
        android:name="androidx.core.content.FileProvider"
        android:exported="false"
        android:grantUriPermissions="true">

        <meta-data android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/file_paths"/>


    </provider>

    <meta-data
        android:name="preloaded_fonts"
        android:resource="@array/preloaded_fonts" />
</application>

</manifest>

解决方法

要使用用户指定的旋转,请使用以下代码:

activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER);

,

请在清单文件中删除 android:screenOrientation="portrait" 否则添加传感器而不是纵向。

或者在整个Activity的manifest中添加android:screenOrientation="sensor"

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...