Android-布局行为属性导致CoordinatorLayout中的FrameLayout与父级不匹配
我的活动在屏幕顶部包含2个Android-布局行为属性导致CoordinatorLayout中的FrameLayout与父级不匹配,android,android-layout,Android,Android Layout,我的活动在屏幕顶部包含2个工具栏,我正在使用协调器布局在回收视图的滚动条上使顶部的一个退出/进入屏幕,而另一个工具栏将始终跟随它,但不会退出屏幕 另一个包含前面提到的RecyclerView的布局将动态添加到FrameLayout容器中。布局来自另一个包,因此我必须将app:layout\u behavior=“@string/appbar\u scrolling\u view\u behavior”添加到FrameLayout容器中,以使用CoordinatorLayout。它工作正常,没有问
工具栏
,我正在使用协调器布局
在回收视图
的滚动条上使顶部的一个退出/进入屏幕,而另一个工具栏
将始终跟随它,但不会退出屏幕
另一个包含前面提到的RecyclerView
的布局将动态添加到FrameLayout
容器中。布局来自另一个包,因此我必须将app:layout\u behavior=“@string/appbar\u scrolling\u view\u behavior”
添加到FrameLayout
容器中,以使用CoordinatorLayout
。它工作正常,没有问题
但是,当我将另一个布局添加到FrameLayout
(例如,一个居中的ProgressBar
)而不是RecyclerView
,错误就出现了。与父项匹配的框架布局
,没有填充屏幕,其高度与进度条
相同
在我删除了行app:layou\u behavior…
之后,FrameLayout
成功地填充了屏幕。但是在运行时,当我想添加一个RecyclerView
时,由于缺少app:layout\u behavior…
属性,它的第一项的一部分被工具栏
阻止
一句话,如果我将app:layou behavior..
属性添加到FrameLayout
中,它的回收视图
显示正确,但FrameLayout
仅在高度上包装内容
;如果没有,它将match_parent
,而RecyclerView
将被第二个工具栏
阻止
请注意,我无法直接将此属性添加到另一个包中的RecyclerView
(但我可以在运行时获取它的引用)
以下是xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/mainToolbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|enterAlways"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
style="@style/Toolbar"
app:theme="@style/Toolbar" />
<android.support.v7.widget.Toolbar
android:id="@+id/subToolbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:theme="@style/Toolbar" />
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
/>
</android.support.design.widget.CoordinatorLayout>
更新:在添加ProgressBar
之前,我已经通过在运行时向FrameLayout
添加一个不可见的新视图(this)
对象解决了这个问题,该对象默认情况下会填充屏幕。但我仍然不知道为什么会出现这个错误。我认为这个解决方案是一个黑客