Android的SupportLib - 中的FrameLayout与CoordinatorLayout消耗AppBarLayout整个屏幕高度 [英] Android SupportLib - FrameLayout in CoordinatorLayout with AppBarLayout consuming entire screen-height

查看:283
本文介绍了Android的SupportLib - 中的FrameLayout与CoordinatorLayout消耗AppBarLayout整个屏幕高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前具有一个问题,一个的FrameLayout CoordinatorLayout 从Android的设计支持库,而我也跟着从这个<一的说明href=\"http://blog.grafixartist.com/material-design-tabs-with-android-design-support-library/\">post在创建标签。

I am currently having an issue with a FrameLayout in a CoordinatorLayout from Android design-support library whereas I followed the instructions from this post while creating the tabs.

基本上大部分的东西如预期,集装箱片段充气到的FrameLayout 和他们的制表片段correclty添加到 ViewPager 作为选项卡(需要这种方式,因为我有很多碎片应该重用布局)。

Basically most things work as expected, the container-fragments are inflated into the FrameLayout and theirs tab-fragments are correclty added to the ViewPager as tabs (need it this way because I have got numerous fragments which should reuse the layout).

我挣扎的问题是,的FrameLayout (并因此也是制表片段)占用整个屏幕高度,使其重叠的工具栏 TabLayout 。为了形象化的问题,我已经创建了下面的图片:

The problem I am struggling with is that the FrameLayout (and as a result also the tab-fragments) consumes the entire screen-height so it overlaps the Toolbar and the TabLayout. In order to visualize the problem I have created the following image:

基本布局与 CoordinatorLayout 工具栏 TabLayout

Base-Layout with CoordinatorLayout, Toolbar, and TabLayout:

<android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appBarLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <include layout="@layout/toolbar" />

        <android.support.design.widget.TabLayout
            android:id="@+id/tabLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </android.support.design.widget.AppBarLayout>

    <FrameLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</android.support.design.widget.CoordinatorLayout>

通过膨胀成容器中的片段中使用的分离的布局

Separate layout used by the fragments inflated into container:

<android.support.v4.view.ViewPager
    android:id="@+id/viewPager"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

所有碎片,我的 BaseFragment 级(关于SO调用另一个帖子 inflater.inflate(getLayoutRes(),空充气); 是导致同样的问题)问题

All fragments are inflated by my BaseFragment-class (on another post on SO calling inflater.inflate(getLayoutRes(), null); was the issue causing the same problem)

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    return inflater.inflate(getLayoutRes(), container, false);
}

如果我更换 CoordinatorLayout 与正常的LinearLayout 的FrameLayout 开始下的 AppBarLayout 如预期,但按该<一个href=\"https://developer.android.com/reference/android/support/design/widget/AppBarLayout.html\">documentation在 AppBarLayout 的大部分功能汇入作业要求将直接子 CoordinatorLayout

If I replace the CoordinatorLayout with a normal LinearLayout the FrameLayout starts below the AppBarLayout as expected but as per the documentation the AppBarLayout for most of it´s features requires to be a direct child of the CoordinatorLayout.

我可以只添加一个 marginTop 的FrameLayout ,但我想知道是否有合适的解决方案为了这。预先感谢任何提示!

I could just add a marginTop to the FrameLayout but I would like to know if there is any appropriate solution for this. Thanks in advance for any hints!

推荐答案

移动你的应用:layout_behavior =@字符串/ appbar_scrolling_view_behavior的FrameLayout - 该属性必须对直接子 CoordinatorLayout

Move your app:layout_behavior="@string/appbar_scrolling_view_behavior" to the FrameLayout - that attribute needs to be on the direct child of the CoordinatorLayout.

这篇关于Android的SupportLib - 中的FrameLayout与CoordinatorLayout消耗AppBarLayout整个屏幕高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆