Android Studio模拟器无法使用横屏模式?

5
以下示例来自项目https://github.com/googlecodelabs/android-navigation,布局文件来自https://github.com/googlecodelabs/android-navigation/tree/master/app/src/main/res
我在Android Studio模拟器中测试了它的竖屏和横屏模式,你可以在A1.pngA2.png中看到结果。
看起来,在Android Studio模拟器中横屏模式不起作用。
我在真实手机上测试了相同的代码,你可以在B1.pngB2.png中看到结果。
真实手机上的横屏模式正常工作,但在使用横屏模式时,Android Studio模拟器有什么问题呢?
顺便提一下,我已经阅读了这篇文章Switching to landscape mode in Android Emulatornavigation_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>

导航活动.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

enter image description here

A2.png

enter image description here

B1.png

enter image description here

B2.png

enter image description here

Added Content

致无名氏:感谢您!

我按照您的方法进行了测试,看起来 Android Studio 3.5 中带有横屏模式的模拟器还不能良好工作。

在带有横屏模式的真实移动电话中,菜单图标不会显示在带有横屏模式的模拟器中,您可以看到 C1.png,为什么呢?而 B2.png 是带有横屏模式的真实移动电话。

C1.png enter image description here

1个回答

10

因为你需要在模拟器控制中点击旋转左/旋转右后,还需要在设备的右下部分设置旋转。

Before

enter image description here

after enter image description here


谢谢!您能否看一下我在问题中添加的内容? - HelloCW
我可以问一下为什么有一个汉堡包样式的“仅在横向方向”吗?你是在代码中添加它吗? - No Name
1
旋转设备和屏幕需要点击两个按钮的意义何在? - AXE
我在右下角没有图标。为什么? - Nam Lê Quý

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接