Toolbar not being pinned in CollapsingToolbarLayout with RecyclerView

Viewed 51

I've created the following collapsing toolbar layout (this picture), but whenever I try to scroll down the toolbar just disappears (this picture). I've been searching the whole day and trying all the possible solutions that I found, but still nothing.

I've tried with different flags, different attributes and nothing. It was working a week ago but at some point it stopped doing fine and I could never figure out why.

My current XML code is the following one:

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/backgroundCards"
    android:fitsSystemWindows="true"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/mainAppBar"
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:fitsSystemWindows="true"
        android:theme="@style/AppTheme">

        <com.google.android.material.appbar.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="@color/colorPrimaryDark"
            app:expandedTitleMarginBottom="20dp"
            app:expandedTitleMarginStart="15dp"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_gravity="center"
                android:orientation="vertical">

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:alpha="0.1"
                    android:contentDescription="@string/app_name"
                    android:fitsSystemWindows="true"
                    android:scaleType="centerCrop"
                    android:src="@drawable/header"
                    app:layout_collapseMode="parallax">
                </ImageView>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:orientation="vertical"
                    android:fitsSystemWindows="true"
                    app:layout_collapseMode="parallax">

                    <com.mikhaellopez.circularimageview.CircularImageView
                        android:id="@+id/nextBirthdayAvatar"
                        android:layout_width="140dp"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:src="@drawable/dog"
                        app:civ_border_color="@color/Black"
                        app:civ_border_width="4dp"
                        app:civ_shadow="true"
                        app:civ_shadow_color="@color/DimGray"
                        app:civ_shadow_radius="3dp"/>
                    <!-- Title, secondary and supporting text -->
                    <TextView
                        android:id="@+id/nextBirthdayName"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:gravity="center"
                        android:text="@string/default_nextbday"
                        android:textAppearance="?attr/textAppearanceBody1"
                        android:textColor="@color/DeepPink"
                        android:textSize="30dp"
                        android:textStyle="bold"/>

                    <TextView
                        android:id="@+id/nextBirthdayDate"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_marginTop="5dp"
                        android:gravity="center"
                        android:text=""
                        android:textAppearance="?attr/textAppearanceBody2"
                        android:textColor="@color/White"
                        android:textSize="27dp"
                        android:textStyle="bold"/>
                </LinearLayout>

                <androidx.appcompat.widget.Toolbar
                    android:id="@+id/mainToolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    app:contentInsetStart="0dp"
                    app:contentInsetStartWithNavigation="0dp"
                    app:layout_collapseMode="pin"
                    app:popupTheme="@style/ToolBarStyle"></androidx.appcompat.widget.Toolbar>
            </FrameLayout>

        </com.google.android.material.appbar.CollapsingToolbarLayout>
    </com.google.android.material.appbar.AppBarLayout>


    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/list"
        android:layout_below="@+id/mainAppBar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:drawSelectorOnTop="false"
        android:overScrollMode="never"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">
    </androidx.recyclerview.widget.RecyclerView>


    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fabImportContacts"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="25dp"
        android:src="@drawable/ic_import_contacts_black_18dp"
        app:backgroundTint="@color/DeepPink"
        app:fabCustomSize="50dp"
        app:layout_anchor="@id/mainAppBar"
        app:layout_anchorGravity="bottom|end|right"
        app:maxImageSize="30dp"
        app:tint="@color/White"></com.google.android.material.floatingactionbutton.FloatingActionButton>

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fabNewUser"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="25dp"
        android:src="@drawable/ic_contact_page_black_18dp"
        app:backgroundTint="@color/DeepPink"
        app:fabCustomSize="50dp"
        app:layout_anchor="@id/mainAppBar"
        app:layout_anchorGravity="bottom|end|right"
        app:maxImageSize="30dp"
        app:tint="@color/White"></com.google.android.material.floatingactionbutton.FloatingActionButton>

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="20dp"
        android:src="@drawable/new_contact_icon"
        app:backgroundTint="@color/DeepPink"
        app:fabCustomSize="55dp"
        app:layout_anchor="@id/mainAppBar"
        app:layout_anchorGravity="bottom|end|right"
        app:maxImageSize="35dp"
        app:tint="@color/White"></com.google.android.material.floatingactionbutton.FloatingActionButton>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

In the MainActivity I have the following code, but I dont think that's the problem.


        setContentView(R.layout.activity_main);
        Toolbar tb = findViewById(R.id.mainToolbar);
        setSupportActionBar(tb);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        tb.setNavigationIcon(R.drawable.ic_exit_to_app);
        tb.setNavigationOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view) {
                Log.d("click", "navigation button");
                signOut();
            }
        });
        getSupportActionBar().setDisplayShowTitleEnabled(false);

Any help would be great, I honestly dont know what else to try, thanks in advance

[UPDATE: SOLUTION] As @PrinceAli said in the comments, the problem was that the Toolbar was inside the FrameLayout, I took it off and its working!

0 Answers
Related