【问题标题】:FrameLayout Shown Above AppBarLayoutAppBarLayout 上方显示的 FrameLayout
【发布时间】:2016-02-02 19:43:34
【问题描述】:

我有一个简单的CoordinatorLayout,带有AppBarLayoutFrameLayout,但是FrameLayout 的内容会显示在AppBarLayout 上,而不管FrameLayout 上的layout_behavior 属性如何。我尝试在其他地方添加该属性(例如在我的RecyclerView 上),但这是相同的行为。

这是一张图片来说明我的意思。

活动布局:

<?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:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay"
            app:layout_scrollFlags="scroll|enterAlways"/>

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

    <FrameLayout
        android:id="@android:id/content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

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

片段布局:

<android.support.v7.widget.RecyclerView
android:id="@+id/checkins_recycler_view"
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:scrollbars="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

我如何在我的活动中添加我的片段:

final UserCheckinsFragment fragment = new UserCheckinsFragment();
    final Bundle arguments = new Bundle();
    UserCheckinsFragment.getArguments(arguments, items);
    fragment.setArguments(arguments);

    getSupportFragmentManager().beginTransaction().add(android.R.id.content, fragment,
            UserCheckinsFragment.class.getName()).commit();

【问题讨论】:

    标签: android android-toolbar android-design-library android-coordinatorlayout


    【解决方案1】:

    xml 中的FrameLayout ID (@android:id/content) 和Fragment 事务中的容器(android.R.id.content) 指的是系统布局的根,然后它会覆盖整个屏幕。

    要解决,请使用不带android 前缀的它们。

    【讨论】:

      【解决方案2】:

      app:layout_behavior="@string/appbar_scrolling_view_behavior" 添加到RecyclerView 即可。 app:layout_behavior 应该是你的 Fragment 布局的根目录

      【讨论】:

      • 不幸的是,将其添加到 RecyclerView 具有相同的行为。
      • 我遇到了同样的问题。我必须将 `app:layout_behavior="@string/appbar_scrolling_view_behavior"` 添加到 Fragment 布局的根目录(在我的情况下是 RelativeLayout),其中包含 RecyclerView 和其他内容
      • 所以我的片段布局的根是我在原始问题中列出的 RecyclerView。添加 layout_behavior 属性不起作用(我将更新问题以反映我使用的内容)。也许我会尝试添加另一个容器布局,看看它是否会起作用。也许值得一试,即使它很老套。
      【解决方案3】:

      https://stackoverflow.com/a/24713989/4409113

      AppCompat 中,没有对ActionBar 的本机支持。 android.R.id.content 是整个应用屏幕的容器。这意味着 - 包括ActionBar,因为ActionBar 在那里模拟并添加为标准视图层次结构。

      你可能想使用(在Layout):

      android:id="@+id/content"
      

      和(在Java):

      getSupportFragmentManager().beginTransaction().add(R.id.content, fragment,
                      UserCheckinsFragment.class.getName()).commit();
      

      那么,它应该可以工作了。

      【讨论】:

        【解决方案4】:

        您好,我遇到了同样的问题,我通过将“app:layout_behavior="@string/appbar_scrolling_view_behavior"‌” 添加到我的布局父级中来修复它,它是线性布局并包含 RecylerView 布局,现在它可以正常工作但我有一个页面boutmn中的按钮消失的其他问题

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2019-04-06
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多