Android Studio 折叠布局的渲染问题

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

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

  1. <androidx.coordinatorlayout.widget.CoordinatorLayout
  2. xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:app="http://schemas.android.com/apk/res-auto"
  4. android:layout_width="match_parent"
  5. android:layout_height="match_parent">
  6. <com.google.android.material.appbar.AppBarLayout
  7. android:id="@+id/appBarLayout"
  8. android:layout_width="match_parent"
  9. android:layout_height="wrap_content"
  10. android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
  11. <com.google.android.material.appbar.CollapsingToolbarLayout
  12. android:layout_width="match_parent"
  13. android:layout_height="wrap_content"
  14. app:layout_scrollFlags="scroll|snap|exitUntilCollapsed"
  15. app:title="@string/app_name">
  16. <ImageView
  17. android:layout_width="match_parent"
  18. android:layout_height="250dp"
  19. android:scaleType="centerCrop"
  20. android:src="@drawable/favorite"
  21. app:layout_collapseMode="parallax" />
  22. <androidx.appcompat.widget.Toolbar
  23. android:layout_width="match_parent"
  24. android:layout_height="?attr/actionBarSize"
  25. app:layout_collapseMode="pin"
  26. app:popupTheme="@style/ThemeOverlay.AppCompat.Dark" />
  27. </com.google.android.material.appbar.CollapsingToolbarLayout>
  28. </com.google.android.material.appbar.AppBarLayout>
  29. <androidx.core.widget.NestedScrollView
  30. android:layout_width="match_parent"
  31. android:layout_height="wrap_content"
  32. app:layout_behavior="@string/appbar_scrolling_view_behavior">
  33. <TextView
  34. android:layout_width="match_parent"
  35. android:layout_height="wrap_content"
  36. android:lineSpacingExtra="8sp"
  37. android:padding="16dp"
  38. android:text="this is text"
  39. android:textSize="20sp" />
  40. </androidx.core.widget.NestedScrollView> </androidx.coordinatorlayout.widget.CoordinatorLayout>

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

  1. java.lang.NoClassDefFoundError: Could not initialize class androidx.core.view.accessibility.AccessibilityNodeInfoCompat$AccessibilityActionCompat
  2. at com.google.android.material.appbar.AppBarLayout$BaseBehavior.updateAccessibilityActions(AppBarLayout.java:1882)
  3. at com.google.android.material.appbar.AppBarLayout$BaseBehavior.setHeaderTopBottomOffset(AppBarLayout.java:2118)
  4. at com.google.android.material.appbar.AppBarLayout$BaseBehavior.setHeaderTopBottomOffset(AppBarLayout.java:1446)
  5. at com.google.android.material.appbar.HeaderBehavior.setHeaderTopBottomOffset(HeaderBehavior.java:158)
  6. at com.google.android.material.appbar.AppBarLayout$BaseBehavior.onLayoutChild(AppBarLayout.java:1781)
  7. at com.google.android.material.appbar.AppBarLayout$Behavior.onLayoutChild(AppBarLayout.java:1427)
  8. at com.google.android.material.appbar.AppBarLayout$BaseBehavior.onLayoutChild(AppBarLayout.java:1446)
  9. at androidx.coordinatorlayout.widget.CoordinatorLayout.onLayout_Original(CoordinatorLayout.java:953)
  10. at androidx.coordinatorlayout.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java)
  11. at android.view.View.layout_Original(View.java:23694)
  12. at android.view.View_Delegate.layout(View_Delegate.java:91)
  13. at android.view.View.layout(View.java:23680)
  14. at android.view.ViewGroup.layout(ViewGroup.java:6413)
  15. at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
  16. at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
  17. at android.view.View.layout_Original(View.java:23694)
  18. at android.view.View_Delegate.layout(View_Delegate.java:91)
  19. at android.view.View.layout(View.java:23680)
  20. at android.view.ViewGroup.layout(ViewGroup.java:6413)
  21. at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1103)
  22. at android.view.View.layout_Original(View.java:23694)
  23. at android.view.View_Delegate.layout(View_Delegate.java:91)
  24. at android.view.View.layout(View.java:23680)
  25. at android.view.ViewGroup.layout(ViewGroup.java:6413)
  26. at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
  27. at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
  28. at android.view.View.layout_Original(View.java:23694)
  29. at android.view.View_Delegate.layout(View_Delegate.java:91)
  30. at android.view.View.layout(View.java:23680)
  31. at android.view.ViewGroup.layout(ViewGroup.java:6413)
  32. at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:377)
  33. at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:450)
  34. at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:122)
  35. at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:701)
  36. at com.android.tools.idea.rendering.RenderTask.lambda$inflate$8(RenderTask.java:848)
  37. at com.android.tools.idea.rendering.RenderExecutor$runAsyncActionWithTimeout$3.run(RenderExecutor.kt:200)
  38. at com.android.tools.idea.rendering.RenderExecutor$PriorityRunnable.run(RenderExecutor.kt:298)
  39. at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
  40. at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
  41. 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”中包含这一行

相关问题