我有一个简单CoordinatorLayout
与AppBarLayout
和FrameLayout
,但FrameLayout
内容被显示在AppBarLayout
无论在FrameLayout
的layout_behavior属性。我尝试在其他地方添加该属性(如在我的RecyclerView
上),但它是相同的行为。的FrameLayout上面显示AppBarLayout
这是一张图片来展示我的意思。
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();
不幸的是,向RecyclerView添加的行为具有相同的行为。 –
我遇到了同样的问题。我必须添加'app:layout_behavior =“@ string/appbar_scrolling_view_behavior”'到Fragment布局的根目录(在我的情况下是一个RelativeLayout),其中包含RecyclerView和其他东西 – Blackbelt
因此,我的片段布局的根目录是RecyclerView,其中I已在原始问题中列出。将layout_behavior属性添加到该行为不起作用(我将更新问题以反映我所用的内容)。也许我会尝试添加另一个容器布局来查看它是否可以工作。值得一试,也许,即使它是hacky。 –