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();
ʍѳђઽ૯ท
  • 16,646
  • 7
  • 53
  • 108
C Nick
  • 2,500
  • 2
  • 17
  • 21

4 Answers4

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.

ʍѳђઽ૯ท
  • 16,646
  • 7
  • 53
  • 108
GPack
  • 2,494
  • 4
  • 19
  • 50
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

Blackbelt
  • 156,034
  • 29
  • 297
  • 305
  • Unfortunately adding that to the RecyclerView has the same behavior. – C Nick Feb 02 '16 at 19:57
  • 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 stuff – Blackbelt Feb 02 '16 at 20:03
  • 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. – C Nick Feb 02 '16 at 20:08
2

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

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.

Community
  • 1
  • 1
ʍѳђઽ૯ท
  • 16,646
  • 7
  • 53
  • 108
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

na3na3iss
  • 65
  • 1
  • 1
  • 10