自动更改活动:Android中的横向和纵向模式

问题描述 投票:0回答:1

我的Android应用中有两项活动。点击后,我可以来回移动一个活动到另一个活动。但是当我从横向模式变为纵向模式时,反之亦然,我的活动会自动更改,这是我没想到的。即使将其更改为纵向或横向模式,我希望它仍然保持相同的活动。那可能是什么问题呢?

更新

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.dmacs.myapplication">

    <application
        android:allowBackup="true"
        android:icon="@drawable/icon1"
        android:label="@string/app_name"
        android:logo="@drawable/icon2"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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


        <activity android:name=".second_main">
        </activity><!-- ATTENTION: This was auto-generated to add Google Play services to your project for
     App Indexing.  See https://g.co/AppIndexing/AndroidStudio for more information. -->
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />


    </application>

</manifest>
android android-activity landscape
1个回答
0
投票
<activity
    android:name=".MainActivity"
    android:screenOrientation="sensor" 
    android:configChanges="orientation"
    android:label="@string/app_name"
    android:theme="@style/AppTheme.NoActionBar">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

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

我只是添加了这一行:android:screenOrientation="sensor"

它会覆盖系统(如果您的系统可以锁定方向)

同时添加以下行:android:configChanges="orientation"

它可以防止由方向触发的任何更新

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