FrameLayout Shown Above AppBarLayout
Asked Answered
P

4

5

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.

enter image description here

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();
Payson answered 2/2, 2016 at 19:43 Comment(0)
C
4

The FrameLayout ID (@android:id/content) in the xml and the container (android.R.id.content) in the Fragment transaction refer to the system root of layout, then it is laid over the all screen.

To solve, use them without android prefix.

Cuffs answered 4/2, 2016 at 6:53 Comment(0)
Y
3

add app:layout_behavior="@string/appbar_scrolling_view_behavior" to the RecyclerView and it will work. The app:layout_behavior should be to the root of the layout's of your Fragment

Yb answered 2/2, 2016 at 19:49 Comment(3)
Unfortunately adding that to the RecyclerView has the same behavior.Payson
I had the same issue with the situation. I had to add ` app:layout_behavior="@string/appbar_scrolling_view_behavior"` to the root of Fragment's layout (in my case was a RelativeLayout) which contained the RecyclerView among other stuffYb
So the root of my fragment's layout is the RecyclerView which I have listed in the original question. Adding the layout_behavior attribute to that didn't work (I'll update the question to reflect what I used). Maybe I'll try to add another container layout to see if it'll work. Worth a shot maybe, even if it is hacky.Payson
P
2

https://mcmap.net/q/729889/-android-r-id-content-as-container-for-fragment

In AppCompat, there is no native support for ActionBar. android.R.id.content is the container of entire app screen. This means - including ActionBar, because ActionBar is emulated there and added as a standard view hierarchy.

You may want to use(In the Layout):

android:id="@+id/content"

And(in Java):

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

Then, it should work.

Paronychia answered 4/2, 2016 at 13:58 Comment(0)
S
0

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

Siva answered 29/3, 2017 at 12:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.