Android Wear:布局在模拟器中显示不正确

Android Wear: Layout is not displaying properly in Emulator

我正在开发 Android 智能手表应用程序。初始屏幕显示正常。但是,当我转到下一个屏幕时,上半部分会弹出类似这样的项目名称。在下图中,Watch 是项目的名称。

我想看到整个屏幕,而不是包含项目名称的白色 space。有谁知道如何解决它以及它为什么会出现?

我的 XML 文件是

<?xml version="1.0" encoding="utf-8"?>
<android.support.wear.widget.BoxInsetLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:deviceIds="wear">

    <LinearLayout
        android:id="@+id/mainContainer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:background="@color/black"
        android:weightSum="1"
        tools:ignore="UselessParent"
        android:layout_alignParentTop="true"
        android:layout_alignParentStart="true">

        <LinearLayout
            android:id="@+id/sign_up_top_bar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:orientation="horizontal"
            android:layout_marginTop="15dp">

            <TextView
                android:id="@+id/textview"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:padding="5dp"
                android:textAlignment="center"
                android:textSize="18sp"
                android:text="@string/text"
                android:background="@color/black"
                android:textColor="@color/white"
                android:fontFamily="Century-Gothic.ttf" />

            <ImageView
                android:id="@+id/imageView1"
                android:layout_width="18dp"
                android:layout_height="19dp"
                android:layout_toRightOf="@+id/text"
                android:src="@drawable/fingerprint" />

        </LinearLayout>

        <Button
            android:layout_marginTop="10dp"
            android:id="@+id/button"
            android:background ="@drawable/roundedbutton"
            android:text="@string/button_text"
            android:layout_width="108dp"
            android:textAlignment="center"
            android:drawablePadding="20dp"
            android:layout_gravity="center"
            android:textColor="@color/white"
            android:layout_height="75dp"
            android:layout_weight="0.34" />


    </LinearLayout>

    </android.support.wear.widget.BoxInsetLayout>

为您的根布局使用 BoxInsetLayout

This class applies the required window insets depending on the screen shape and lets you easily align views on the center or near the edges of the screen.

我强烈建议您通读本教程。

编辑 2:

您需要使用:

android.support.wearable.view.BoxInsetLayout

不是:

android.support.wear.widget.BoxInsetLayout

并添加到 mainContainer:

app:layout_box="all"

<android.support.wearable.view.BoxInsetLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:deviceIds="wear">

<LinearLayout
    app:layout_box="all"
    android:id="@+id/mainContainer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@color/black"
    android:weightSum="1"
    tools:ignore="UselessParent"
    android:layout_alignParentTop="true"
    android:layout_alignParentStart="true">

问题的答案很简单。一天后我想通了。我在清单文件中将主题从 Theme.AppCompat.Light 更改为 Theme.AppCompat.Light.NoActionBar 。程序名称栏消失了。