androidandroid-layoutandroid-collapsingtoolbarlayoutandroid-layout-editorandroid-rendering

Render problem due to Collapsing Toolbar in Android Studio


My Layout editor doesn't render this layout with collapsing toolbar, other layouts render just fine. I have tried refreshing, invalidate cache/restart, gradle implementations to stable versions, set the API 29 and 28 for preview instead of 30, sync project with gradle files, switched to new/experimental rendering engine. Nothing has worked so far. The issue seems to be due to Collapsing Toolbar as seen in the stack trace below.

java.lang.NullPointerException
    at android.view.ViewGroup.brokenDispatchApplyWindowInsets(ViewGroup.java:7200)
    at android.view.ViewGroup.dispatchApplyWindowInsets(ViewGroup.java:7193)
    at android.view.ViewGroup.brokenDispatchApplyWindowInsets(ViewGroup.java:7203)
    at android.view.ViewGroup.dispatchApplyWindowInsets(ViewGroup.java:7193)
    at android.view.ViewGroup.brokenDispatchApplyWindowInsets(ViewGroup.java:7203)
    at android.view.ViewGroup.dispatchApplyWindowInsets(ViewGroup.java:7193)
    at android.view.ViewGroup.brokenDispatchApplyWindowInsets(ViewGroup.java:7203)
    at android.view.ViewGroup.dispatchApplyWindowInsets(ViewGroup.java:7193)
    at android.view.ViewGroup.brokenDispatchApplyWindowInsets(ViewGroup.java:7203)
    at android.view.ViewGroup.dispatchApplyWindowInsets(ViewGroup.java:7193)
    at android.view.ViewRootImpl.dispatchApplyInsets(ViewRootImpl.java:1925)
    at android.view.ViewRootImpl_Accessor.dispatchApplyInsets(ViewRootImpl_Accessor.java:24)
    at com.android.layoutlib.bridge.impl.Layout.requestFitSystemWindows(Layout.java:385)
    at android.view.View.requestFitSystemWindows(View.java:10796)
    at android.view.View.requestFitSystemWindows(View.java:10796)
    at android.view.View.requestFitSystemWindows(View.java:10796)
    at android.view.View.requestFitSystemWindows(View.java:10796)
    at android.view.View.requestApplyInsets(View.java:10804)
    at androidx.core.view.ViewCompat.requestApplyInsets(ViewCompat.java:2426)
    at androidx.core.view.ViewCompat$Api21Impl$1.onApplyWindowInsets(ViewCompat.java:4774)
    at android.view.View.dispatchApplyWindowInsets(View.java:10514)
    at android.view.ViewGroup.dispatchApplyWindowInsets(ViewGroup.java:7191)
    at android.view.ViewGroup.brokenDispatchApplyWindowInsets(ViewGroup.java:7203)
    at android.view.ViewGroup.dispatchApplyWindowInsets(ViewGroup.java:7193)
    at android.view.ViewGroup.brokenDispatchApplyWindowInsets(ViewGroup.java:7203)
    at android.view.ViewGroup.dispatchApplyWindowInsets(ViewGroup.java:7193)
    at android.view.ViewGroup.brokenDispatchApplyWindowInsets(ViewGroup.java:7203)
    at android.view.ViewGroup.dispatchApplyWindowInsets(ViewGroup.java:7193)
    at android.view.ViewGroup.brokenDispatchApplyWindowInsets(ViewGroup.java:7203)
    at android.view.ViewGroup.dispatchApplyWindowInsets(ViewGroup.java:7193)
    at android.view.ViewRootImpl.dispatchApplyInsets(ViewRootImpl.java:1925)
    at android.view.ViewRootImpl_Accessor.dispatchApplyInsets(ViewRootImpl_Accessor.java:24)
    at com.android.layoutlib.bridge.impl.Layout.requestFitSystemWindows(Layout.java:385)
    at android.view.View.requestFitSystemWindows(View.java:10796)
    at android.view.View.requestFitSystemWindows(View.java:10796)
    at android.view.View.requestFitSystemWindows(View.java:10796)
    at android.view.View.requestFitSystemWindows(View.java:10796)
    at android.view.View.requestFitSystemWindows(View.java:10796)
    at android.view.View.requestApplyInsets(View.java:10804)
    at androidx.core.view.ViewCompat.requestApplyInsets(ViewCompat.java:2426)
    at com.google.android.material.appbar.CollapsingToolbarLayout.onAttachedToWindow(CollapsingToolbarLayout.java:273)
    at android.view.View.dispatchAttachedToWindow(View.java:19575)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3430)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3437)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3437)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3437)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3437)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3437)
    at android.view.AttachInfo_Accessor.setAttachInfo(AttachInfo_Accessor.java:42)
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:335)
    at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:373)
    at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:141)
    at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:713)
    at com.android.tools.idea.rendering.RenderTask.lambda$inflate$6(RenderTask.java:844)
    at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1604)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)

Layout causing the issue


<?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:id="@+id/coordinatorLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/background_light">
    <!--    android:fitsSystemWindows="true"-->


    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/white"
        android:minHeight="?attr/actionBarSize"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
        <!--            android:fitsSystemWindows="true"-->

        <com.google.android.material.appbar.CollapsingToolbarLayout
            android:id="@+id/collapsingToolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:collapsedTitleGravity="center"
            app:collapsedTitleTextAppearance="@style/collapsedBlackTitle"
            app:contentScrim="@color/white"
            app:expandedTitleGravity="center"
            app:expandedTitleMarginEnd="64dp"
            app:expandedTitleMarginStart="48dp"
            app:expandedTitleTextAppearance="@style/expandedWhiteTitle"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            .
            .
            .

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

        <!--- ADD TAB_LAYOUT HERE -->
        <com.google.android.material.tabs.TabLayout
            android:id="@+id/tabLayoutMedia"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            app:layout_constraintBottom_toTopOf="@id/recycleView"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/view5"
            app:tabIconTint="@color/selected_orange_item">

            .
            .
            .
            
        </com.google.android.material.tabs.TabLayout>

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

    <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
        android:id="@+id/swipe_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/postsConstraintLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/recycler_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                app:layout_behavior="@string/appbar_scrolling_view_behavior"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"

                />

            <TextView
                android:id="@+id/tvNoPosts"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="@dimen/_16sdp"
                android:gravity="center"
                android:text="No Posts"
                android:textSize="20sp"
                android:visibility="visible"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintVertical_bias="0.1" />

        </androidx.constraintlayout.widget.ConstraintLayout>
    </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>


    <androidx.cardview.widget.CardView
        android:id="@+id/cardView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:clickable="true"
        android:focusable="true"
        android:foreground="?android:attr/selectableItemBackground"
        android:visibility="gone"
        app:cardBackgroundColor="@color/colorPrimary"
        app:cardCornerRadius="30dp"
        app:cardElevation="10dp"
        app:layout_anchor="@id/appbar"
        app:layout_anchorGravity="bottom|center_horizontal|clip_horizontal"
        app:layout_constraintEnd_toEndOf="@+id/imageView16"
        app:layout_constraintStart_toStartOf="@+id/imageView16"
        app:layout_constraintTop_toBottomOf="@+id/imageView16">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:paddingHorizontal="70dp"
            android:paddingVertical="15dp"
            android:text="Play All"
            android:textAllCaps="true"
            android:textColor="@color/white"
            android:textSize="22sp"
            android:textStyle="bold" />
    </androidx.cardview.widget.CardView>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

relevant gradle implementations

    implementation 'com.google.android.material:material:1.3.0'

Solution

  • Go to File -> Project Structure -> Suggestions -> find all the relevant libraries and Update to the most stable version, in my case it was the appcompat. Viola! the rendering engine was able to render the layout, although it shows Path.op() as another problem but it works.

    enter image description here