6

我有一个简单CoordinatorLayoutAppBarLayoutFrameLayout,但FrameLayout内容被显示在AppBarLayout无论在FrameLayout的layout_behavior属性。我尝试在其他地方添加该属性(如在我的RecyclerView上),但它是相同的行为。的FrameLayout上面显示AppBarLayout

这是一张图片来展示我的意思。

enter image description here

Activitiy布局:

<?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(); 

回答

4

FrameLayout ID(@android:id/content)的布局的根指系统根布局,那么它放置在所有屏幕上。

要解决,请在没有android前缀的情况下使用它们。

3

app:layout_behavior="@string/appbar_scrolling_view_behavior"添加到RecyclerView,它将起作用。该app:layout_behavior应该是在XML和在Fragment交易容器(android.R.id.content)在您的Fragment

+0

不幸的是,向RecyclerView添加的行为具有相同的行为。 –

+0

我遇到了同样的问题。我必须添加'app:layout_behavior =“@ string/appbar_scrolling_view_behavior”'到Fragment布局的根目录(在我的情况下是一个RelativeLayout),其中包含RecyclerView和其他东西 – Blackbelt

+0

因此,我的片段布局的根目录是RecyclerView,其中I已在原始问题中列出。将layout_behavior属性添加到该行为不起作用(我将更新问题以反映我所用的内容)。也许我会尝试添加另一个容器布局来查看它是否可以工作。值得一试,也许,即使它是hacky。 –

1

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(); 

然后,它应该工作。

0

嗨我有同样的问题,我通过添加“应用程序:layout_behavior =”@字符串/ appbar_scrolling_view_behavior“”到我的布局父母这是线性布局和包含RecylerView布局,现在它可以正常工作,但我有另一个问题是,在页面的boutmn中的按钮将消失