BoxInsetLayout不起作用

Mal*_*der 6 android android-layout wear-os

我在android studio v1.2.2中创建了示例android穿戴活动项目.我删除了WatchViewStub,并使用此示例使用BoxInsetLayout创建活动.但是BoxInsetLayout在Round Device上无法正常工作.我在moto 360 android 5.1.1和moto 360 5.0.1版更新之前对此进行了测试.我在模拟器上测试了这个.它根本不起作用.我一直看到这个:

但一定是这个

我的代码如下:

activity_main.xml中

<android.support.wearable.view.BoxInsetLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:padding="15dp">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="5dp"
        android:background="@color/red"
        app:layout_box="all">

        <TextView
            android:gravity="center"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:text="Hello Android Wear"
            android:textColor="@color/black" />

        <ImageButton
            android:background="@drawable/selector_btn_ok"
            android:layout_gravity="bottom|start"
            android:layout_height="50dp"
            android:layout_width="50dp" />

        <ImageButton
            android:background="@drawable/selector_btn_cancel"
            android:layout_gravity="bottom|end"
            android:layout_height="50dp"
            android:layout_width="50dp" />
    </FrameLayout>
</android.support.wearable.view.BoxInsetLayout>
Run Code Online (Sandbox Code Playgroud)

为什么不起作用?我在哪里弄错了?如何在圆形屏幕设备上正确使用BoxInsetLayout?

Way*_*ski 2

错误出现在您的 Activity_main.xml 中,您在其中指定了:

android:padding="15dp"
Run Code Online (Sandbox Code Playgroud)

如果你删除它,那么它应该可以工作。BoxInsetLayout 在实现中使用填充,并且您更改了该值,该值给出了您观察到的不正确的输出。

(编辑)值得注意的是,BoxInsetLayout 会调整自身以及子视图的填充。因此,请确保不要更改填充值,否则会损坏。如果您想更好地控制填充,可以尝试嵌入第二个 FrameLayout。