I have a simple CoordinatorLayout
with a AppBarLayout
and FrameLayout
, but the FrameLayout
contents are being displayed over the AppBarLayout
regardless of the layout_behavior attribute on the FrameLayout
. I've tried adding that attribute elsewhere (like on my RecyclerView
), but it's the same behavior.
Here's a picture to show what I mean.
Activitiy Layout:
<?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>
Fragment Layout:
<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"/>
How I add my fragment in my Activity:
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();
Hi i had the same problem and i fixed it by adding"app:layout_behavior="@string/appbar_scrolling_view_behavior"" into my layout parent which is linear layout and contain the RecylerView Layout and now it works correctly but i have an other problem that the button which is in the boutmn of the page disapear
https://stackoverflow.com/a/24713989/4409113
You may want to use(In the
Layout
):And(in
Java
):Then, it should work.
The
FrameLayout
ID (@android:id/content
) in the xml and the container (android.R.id.content
) in theFragment
transaction refer to the system root of layout, then it is laid over the all screen.To solve, use them without
android
prefix.add
app:layout_behavior="@string/appbar_scrolling_view_behavior"
to theRecyclerView
and it will work. Theapp:layout_behavior
should be to the root of the layout's of yourFragment