横向模式在 Android Studio 模拟器中不起作用?

landscape mode not working in Android Studio Emulator?

以下示例来自项目https://github.com/googlecodelabs/android-navigation, and layout file is from https://github.com/googlecodelabs/android-navigation/tree/master/app/src/main/res

我在Android Studio Emulator 中测试了纵向和横向模式,你可以在A1.png 看到结果A2.png.

横向模式似乎在 Android Studio Emulator 中不起作用。

我在真实手机上测试了相同的代码phone,你可以在B1.png[=98=看到结果]

横向模式在真实移动设备中运行良好phone,当我使用横向模式时 Android Studio Emulator 有什么问题?

顺便说一句,我已经阅读了这篇文章Switching to landscape mode in Android Emulator

navigation_activity.xml

<androidx.drawerlayout.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.android.codelabs.navigation.MainActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorPrimary"
            android:theme="@style/ThemeOverlay.MaterialComponents.Dark.ActionBar" />

        <fragment
            android:id="@+id/my_nav_host_fragment"
            android:name="androidx.navigation.fragment.NavHostFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:defaultNavHost="true"
            app:navGraph="@navigation/mobile_navigation" />
    </LinearLayout>

    <com.google.android.material.navigation.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:menu="@menu/nav_drawer_menu" />

</androidx.drawerlayout.widget.DrawerLayout>

navigation_activity.xml (h470dp)

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.example.android.codelabs.navigation.MainActivity">

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimary"
        android:theme="@style/ThemeOverlay.MaterialComponents.Dark.ActionBar" />

    <fragment
        android:id="@+id/my_nav_host_fragment"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        app:defaultNavHost="true"
        app:navGraph="@navigation/mobile_navigation" />

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottom_nav_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:menu="@menu/bottom_nav_menu" />
</LinearLayout>

navigation_activity.xml (w960dp)

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.android.codelabs.navigation.MainActivity">

    <com.google.android.material.navigation.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_alignParentStart="true"
        app:elevation="0dp"
        app:headerLayout="@layout/nav_view_header"
        app:menu="@menu/nav_drawer_menu" />

    <View
        android:layout_width="1dp"
        android:layout_height="match_parent"
        android:layout_toEndOf="@id/nav_view"
        android:background="?android:attr/listDivider" />

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toEndOf="@id/nav_view"
        android:background="@color/colorPrimary"
        android:theme="@style/ThemeOverlay.MaterialComponents.Dark.ActionBar" />

    <fragment
        android:id="@+id/my_nav_host_fragment"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/toolbar"
        android:layout_toEndOf="@id/nav_view"
        app:defaultNavHost="true"
        app:navGraph="@navigation/mobile_navigation" />
</RelativeLayout>

A1.png

A2.png

B1.png

B2.png

添加内容

无名致辞:谢谢!

按照你的方式测试了一下,好像AndroidStudio 3.5的横屏模拟器还不太好用

真实手机phone横向模式下的菜单图标在模拟器横向模式下不显示,你可以看到C1.png,为什么? B2.png 是真正的手机 phone 横向模式

C1.png

因为在模拟器控件中点击左旋/右旋后还需要在右下角设置设备内部的旋转

之前

之后