我目前在Android设计支持库的CoordinatorLayout中遇到了一个FrameLayout的问题,而在创建选项卡时,我遵循了这个
post的指示。
基本上大多数事情按预期工作,容器片段被充填到FrameLayout中,并且它们的标签片段相关性被添加到ViewPager作为选项卡(需要这样做,因为我有很多片段,应该重用布局)。
我正在努力的问题是FrameLayout(结果也是tab片段)消耗整个屏幕高度,所以它与工具栏和TabLayout重叠。为了可视化问题,我创建了以下图像:
Base-Layout with CoordinatorLayout,Toolbar和TabLayout:
android:layout_width="match_parent"
android:layout_height="match_parent">
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
由容器中膨胀的碎片分开使用的布局:
android:id="@+id/viewPager"
android:layout_height="match_parent"
android:layout_width="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
所有的片段都被我的BaseFragment类(在另一个帖子上,称为inflater.inflate(getLayoutRes(),null);是导致同样问题的问题)
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(getLayoutRes(), container, false);
}
如果我将CoordinatorLayout替换为一个正常的LinearLayout,FrameLayout将按照预期的方式在AppBarLayout下方开始,但是按照documentation,AppBarLayout对于大多数的功能需要是CoordinatorLayout的直接孩子。
我可以添加一个marginTop到FrameLayout,但我想知道是否有任何适当的解决方案。提前感谢任何提示!