由于 Android Studio 中的折叠工具栏导致渲染问题
Render problem due to Collapsing Toolbar in Android Studio
我的布局编辑器不呈现带有折叠工具栏的布局,其他布局呈现得很好。我尝试刷新,使 cache/restart、gradle 实现无效到稳定版本,将 API 29 和 28 设置为预览而不是 30,将项目与 gradle 文件同步,切换到new/experimental 渲染引擎。到目前为止没有任何效果。问题似乎是由折叠工具栏引起的,如下面的堆栈跟踪所示。
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.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(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)
导致问题的布局
<?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>
相关gradle 实现
implementation 'com.google.android.material:material:1.3.0'
转到文件 -> 项目结构 -> 建议 -> 找到所有相关库并更新到最稳定的版本,在我的例子中是 appcompat。中提琴!渲染引擎能够渲染布局,尽管它显示 Path.op() 是另一个问题,但它有效。
我的布局编辑器不呈现带有折叠工具栏的布局,其他布局呈现得很好。我尝试刷新,使 cache/restart、gradle 实现无效到稳定版本,将 API 29 和 28 设置为预览而不是 30,将项目与 gradle 文件同步,切换到new/experimental 渲染引擎。到目前为止没有任何效果。问题似乎是由折叠工具栏引起的,如下面的堆栈跟踪所示。
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.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(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)
导致问题的布局
<?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>
相关gradle 实现
implementation 'com.google.android.material:material:1.3.0'
转到文件 -> 项目结构 -> 建议 -> 找到所有相关库并更新到最稳定的版本,在我的例子中是 appcompat。中提琴!渲染引擎能够渲染布局,尽管它显示 Path.op() 是另一个问题,但它有效。