Android Studio 折叠布局的渲染问题

zzoitvuj  于 2023-11-21  发布在  Android
关注(0)|答案(1)|浏览(226)

我有项目和一个片段使用折叠布局.直到最近,一切都很好.但最后一次我面对在Android Studio与折叠布局的渲染问题.例如下面的布局的例子:

<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.google.android.material.appbar.AppBarLayout
    android:id="@+id/appBarLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <com.google.android.material.appbar.CollapsingToolbarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_scrollFlags="scroll|snap|exitUntilCollapsed"
        app:title="@string/app_name">

        
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="250dp"
            android:scaleType="centerCrop"
            android:src="@drawable/favorite"
            app:layout_collapseMode="parallax" />
        
        <androidx.appcompat.widget.Toolbar
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Dark" />

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

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

<androidx.core.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">
    
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:lineSpacingExtra="8sp"
        android:padding="16dp"
        android:text="this is text"
        android:textSize="20sp" />
</androidx.core.widget.NestedScrollView> </androidx.coordinatorlayout.widget.CoordinatorLayout>

字符串
问题是NestedScrollView在Android Studio中渲染后隐藏,有时会在我删除下一个提示时出现:
app:layout_behavior="@string/appbar_scrolling_view_behavior”
但它出现在片段的左上角。Android Studio显示下一个错误:

java.lang.NoClassDefFoundError: Could not initialize class androidx.core.view.accessibility.AccessibilityNodeInfoCompat$AccessibilityActionCompat
at com.google.android.material.appbar.AppBarLayout$BaseBehavior.updateAccessibilityActions(AppBarLayout.java:1882)
at com.google.android.material.appbar.AppBarLayout$BaseBehavior.setHeaderTopBottomOffset(AppBarLayout.java:2118)
at com.google.android.material.appbar.AppBarLayout$BaseBehavior.setHeaderTopBottomOffset(AppBarLayout.java:1446)
at com.google.android.material.appbar.HeaderBehavior.setHeaderTopBottomOffset(HeaderBehavior.java:158)
at com.google.android.material.appbar.AppBarLayout$BaseBehavior.onLayoutChild(AppBarLayout.java:1781)
at com.google.android.material.appbar.AppBarLayout$Behavior.onLayoutChild(AppBarLayout.java:1427)
at com.google.android.material.appbar.AppBarLayout$BaseBehavior.onLayoutChild(AppBarLayout.java:1446)
at androidx.coordinatorlayout.widget.CoordinatorLayout.onLayout_Original(CoordinatorLayout.java:953)
at androidx.coordinatorlayout.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java)
at android.view.View.layout_Original(View.java:23694)
at android.view.View_Delegate.layout(View_Delegate.java:91)
at android.view.View.layout(View.java:23680)
at android.view.ViewGroup.layout(ViewGroup.java:6413)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
at android.view.View.layout_Original(View.java:23694)
at android.view.View_Delegate.layout(View_Delegate.java:91)
at android.view.View.layout(View.java:23680)
at android.view.ViewGroup.layout(ViewGroup.java:6413)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1103)
at android.view.View.layout_Original(View.java:23694)
at android.view.View_Delegate.layout(View_Delegate.java:91)
at android.view.View.layout(View.java:23680)
at android.view.ViewGroup.layout(ViewGroup.java:6413)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
at android.view.View.layout_Original(View.java:23694)
at android.view.View_Delegate.layout(View_Delegate.java:91)
at android.view.View.layout(View.java:23680)
at android.view.ViewGroup.layout(ViewGroup.java:6413)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:377)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:450)
at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:122)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:701)
at com.android.tools.idea.rendering.RenderTask.lambda$inflate$8(RenderTask.java:848)
at com.android.tools.idea.rendering.RenderExecutor$runAsyncActionWithTimeout$3.run(RenderExecutor.kt:200)
at com.android.tools.idea.rendering.RenderExecutor$PriorityRunnable.run(RenderExecutor.kt:298)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:833)


我所做的:

  • 无效高速缓存
  • 清理和重建项目

我还尝试创建新的空项目,并测试它的布局代码和新项目的工作正确。
请告诉我如何解决这个问题?

xwbd5t1u

xwbd5t1u1#

我也遇到了同样的问题。下面是我对预览错误的解决方案:
tools:layout_behavior=“com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior”
在你的“com.google.android.material.appbar.AppBarLayout”中包含这一行

相关问题