Skip to content

Instantly share code, notes, and snippets.

@appoll
Last active October 12, 2023 18:29
Show Gist options
  • Save appoll/d863a09f25076061e881 to your computer and use it in GitHub Desktop.
Save appoll/d863a09f25076061e881 to your computer and use it in GitHub Desktop.
Working sample of fragment inside CoordinatorLayout
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.AppBarLayout>
<fragment
android:id="@+id/some_fragment"
android:name="de.no.no.fragments.SomeFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout="@layout/some_fragment"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
/>
</android.support.design.widget.CoordinatorLayout>
@LuizGadao
Copy link

Fragment layout behavior not work.

@marlonlom
Copy link

@LuizGadao the fragment must be inside a nestesscrollview... or a framelayout, w/ app:layout_behaviour in it.

@catsoft
Copy link

catsoft commented Dec 3, 2018

Working for me

@kochchy
Copy link

kochchy commented Jan 15, 2020

not working

@kochchy
Copy link

kochchy commented Jan 15, 2020

wrapping in the nestedScrollview helps !!

<androidx.core.widget.NestedScrollView
                            android:layout_width="match_parent"
                            android:layout_height="0dp"
                            android:layout_weight="1"
                        android:fillViewport="true"
                        android:fitsSystemWindows="true"
                        app:layout_behavior="@string/appbar_scrolling_view_behavior">

                           <fragment
                                android:id="@+id/home_fragment"
                                android:name="de.no.no.fragments.SomeFragment"
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"/>

                        </androidx.core.widget.NestedScrollView>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment