Can´t place image behind statusbar with motion layout

I´m setting up an appbarlayout with a motionlayout inside which collapse on scroll. For that I´m trying to place a image inside the appbarlayout behind a transparent statusbar. When I was using a collapsable toolbar everything worked fine and I was able to place a image behind the statusbar. Unfortunately the same logic semms to won´t work on my new appbarlayout.

I tried to set fitsSystemWindows=true in different combinations but I´m not able to place the image behind the statusbar. In some cases the whole view goes behindthe statubar but I´m only trying to set the image behind it and the other views below the statusbar. As mentioned I tried fitssystemwindows.

I would be thankful for any help!

To be able to bput something behind the statusbar the first line of my onCreate looks like that

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
    //requireActivity().window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
    //        WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
    WindowCompat.setDecorFitsSystemWindows(requireActivity().window, false)

My layout code for my toolbar looks like this

<androidx.coordinatorlayout.widget.CoordinatorLayout
            android:id="@+id/event_coordinator_layout"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:animateLayoutChanges="true"
            app:layout_constraintBottom_toTopOf="@id/bottomMenu"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">

            <com.google.android.material.appbar.AppBarLayout
                android:id="@+id/maintoolbarholder"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:popupTheme="@style/MyActionBar"
                android:minHeight="?attr/actionBarSize"
     
                android:gravity="top">

                <androidx.constraintlayout.motion.widget.MotionLayout
                    android:id="@+id/event_holder_motionlayout"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@color/white"
                    app:layoutDescription="@xml/fragment_event_holder_scene">

                    <ImageButton
                        android:id="@+id/backButton"
                        android:layout_width="45dp"
                        android:layout_height="45dp"
                        android:adjustViewBounds="true"
                        android:background="@null"
                        android:elevation="5dp"
                        android:forceHasOverlappingRendering="true"
                        android:src="@drawable/ic_back_arrow"
                        app:layout_constraintBottom_toBottomOf="@id/toolbar"
                        app:layout_constraintLeft_toLeftOf="parent"
                        app:layout_constraintTop_toTopOf="@id/toolbar" />

                    <ImageButton
                        android:id="@+id/like_buttonholder"
                        SelectedButtonState="@{Event.state}"
                        android:layout_width="45dp"
                        android:fitsSystemWindows="true"
                        android:layout_height="45dp"
                        android:adjustViewBounds="false"
                        android:background="@null"
                        android:src="@drawable/heartanimation"
                        app:layout_constraintRight_toRightOf="parent"
                        app:layout_constraintTop_toTopOf="@id/guidline_image" />

                    <ImageView
                        android:id="@+id/eventdetailsimage"
                        android:layout_width="0dp"
                        android:layout_height="0dp"
                        android:adjustViewBounds="true"
                        android:scaleType="centerCrop"
                        android:src="@{Event.image}"
                        app:layout_constraintBottom_toBottomOf="@id/guidline_image"
                        app:layout_constraintLeft_toLeftOf="parent"
                        app:layout_constraintRight_toRightOf="parent"
                        app:layout_constraintTop_toTopOf="parent" />


                    <TextView
                        android:id="@+id/expanded_title"
                        android:layout_width="wrap_content"
                        android:layout_height="0dp"
                        android:layout_marginStart="10dp"
                        android:layout_marginTop="10dp"
                        android:layout_marginBottom="5dp"
                        android:fontFamily="@font/open_sans"
                        android:textColor="@color/black"
                        android:textSize="24sp"
                        app:layout_constraintLeft_toLeftOf="parent"
                        app:layout_constraintTop_toBottomOf="@id/like_buttonholder"
                        tools:text="@{Event.name}" />

                    <TextView
                        android:id="@+id/likecounter"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginEnd="10dp"
                        android:textColor="@color/quantum_grey700"
                        android:textSize="16sp"
                        app:layout_constraintBottom_toBottomOf="@+id/like_buttonholder"
                        app:layout_constraintRight_toLeftOf="@id/like_buttonholder"
                        app:layout_constraintTop_toTopOf="@+id/like_buttonholder"
                        tools:text="@{Integer.toString(Event.Likes)}" />

                    <View
                        android:id="@+id/event_holder_toolbar"
                        android:layout_width="match_parent"
                        android:layout_height="0dp"
                        android:background="@color/colorPrimary"
                        android:elevation="4dp"
                        android:alpha="0"
                        app:layout_constraintBottom_toTopOf="@id/guidline_toolbar_bottom"
                        app:layout_constraintLeft_toLeftOf="parent"
                        app:layout_constraintRight_toRightOf="parent"
                        app:layout_constraintTop_toTopOf="parent" />

                    <androidx.constraintlayout.widget.Guideline
                        android:id="@+id/guidline_image"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal"
                        app:layout_constraintGuide_begin="250dp" />

                    <androidx.constraintlayout.widget.Guideline
                        android:id="@+id/guidline_toolbar_bottom"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal"
                        app:layout_constraintGuide_begin="56dp" />

                    <com.google.android.material.tabs.TabLayout
                        android:id="@+id/eventholder_tablayout"
                        android:layout_width="match_parent"
                        android:layout_height="30dp"
                        app:layout_constraintBottom_toBottomOf="parent"
                        app:layout_constraintLeft_toLeftOf="parent"
                        app:layout_constraintRight_toRightOf="parent"
                        app:layout_constraintTop_toBottomOf="@id/expanded_title" />
                </androidx.constraintlayout.motion.widget.MotionLayout>
            </com.google.android.material.appbar.AppBarLayout>

That is how it looks like: enter image description here

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum