Android BoxInsetLayout不';行不通
我在android studio v1.2.2中创建了示例android wear活动项目。我删除了WatchViewStub并使用BoxInsetLayout创建活动。但BoxInsetLayout在圆形设备上无法正常工作。我在Moto360安卓5.1.1上测试了这个,在Moto360版本5.0.1更新之前。我在模拟器上测试了这个。而且根本不起作用。我每次看到这个: 但一定是这样 我的代码如下: activity_main.xmlAndroid BoxInsetLayout不';行不通,android,android-layout,wear-os,Android,Android Layout,Wear Os,我在android studio v1.2.2中创建了示例android wear活动项目。我删除了WatchViewStub并使用BoxInsetLayout创建活动。但BoxInsetLayout在圆形设备上无法正常工作。我在Moto360安卓5.1.1上测试了这个,在Moto360版本5.0.1更新之前。我在模拟器上测试了这个。而且根本不起作用。我每次看到这个: 但一定是这样 我的代码如下: activity_main.xml <android.support.wearable.
<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>
为什么不起作用?我哪里弄错了?如何在具有圆形屏幕的设备上正确使用BoxInsetLayout?错误在于您的activity_main.xml,其中您指定了:
android:padding="15dp"
如果你删除这个,那么它应该可以工作。BoxInsetLayout在实现中使用填充,并且您已经更改了值,该值给出了您观察到的不正确的输出
(编辑)
请务必注意,BoxInsetLayout会调整其本身以及子视图中的填充。因此,请确保不要更改填充值,否则会损坏。如果希望对填充有更多的控制,可以尝试嵌入第二个框架布局。I已删除
android:padding=“15dp
”
如前所述,来自BoxInsettLayout。现在BoxInsetLayout工作正常,但我遇到了一个新问题:android:padding=“5dp”
在FrameLayout中不工作。我尝试了活动_布局,添加了id,并将填充更改为20dp,我得到了圆形和方形屏幕的结果:
这是我的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_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/first_frame_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/red"
android:padding="20dp"
app:layout_box="all">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Hello Android Wear"
android:textColor="@color/black" />
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="bottom|start"
android:background="@drawable/selector_btn_ok" />
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="bottom|end"
android:background="@drawable/selector_btn_cancel" />
</FrameLayout>
</android.support.wearable.view.BoxInsetLayout>
现在。它在方形和圆形屏幕上的工作方式符合我的要求。感谢您的支持!也许你知道为什么填充在FrameLayout中不起作用吗?这对我根本不起作用。我已经在我的项目中复制粘贴了这个xml,但是仍然得到了相同的结果,没有插入。谢谢。但在文档中解释了为什么
BoxInsetLayout
需要15dp填充。谷歌需要纠正guideBoxInsetLayout在其自身和子系统中使用的填充技巧。正如您所看到的,您不应该更改这些填充值,否则会出现问题。我见过的解决这些问题的最好方法是嵌入第二个框架布局,就像你在这里建议的那样,并调整该布局的填充。@WaynePiekarski,在问题中提到过,当时已经非常过时了?或者,如果不能正确处理填充,是最近的倒退吗?
<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_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/first_frame_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/red"
app:layout_box="all">
<FrameLayout
android:id="@+id/second_frame_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/green"
android:padding="5dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Hello Android Wear"
android:textColor="@color/black" />
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="bottom|start"
android:background="@drawable/selector_btn_ok" />
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="bottom|end"
android:background="@drawable/selector_btn_cancel" />
</FrameLayout>
</FrameLayout>
</android.support.wearable.view.BoxInsetLayout>