3

我一直在尝试使用 AppBarLayout 和折叠工具栏创建一个折叠工具栏。

一旦 AppBarLayout 组件被添加到项目中,布局编辑器就不会呈现,我注意到它与其他一些组件一起使用,例如 FAB,但我可以删除 FAB 并在完成创建布局后添加它。该错误仅在渲染中,当我运行该应用程序时,它运行良好。

我尝试使用包含 AppBarLayout 和折叠工具栏的默认滚动活动创建一个新项目,但布局仍然没有呈现,它只会在删除 AppBarLayout 后呈现,删除和添加它可能会暂时解决问题,但在一些构建或更改问题返回,并且布局不会再次在布局编辑器中呈现。

我试图通过单击文件-> 使缓存无效来解决该问题。它已经解决了一段时间的问题,但是在添加了一些带有约束的约束后,布局问题再次出现。

一些默认的滚动活动内容,包括应用栏布局和折叠工具栏

    <com.google.android.material.appbar.AppBarLayout
            android:id="@+id/app_bar"
            android:fitsSystemWindows="true"
            android:layout_height="@dimen/app_bar_height"
            android:layout_width="match_parent"
            android:theme="@style/AppTheme.AppBarOverlay">

        <com.google.android.material.appbar.CollapsingToolbarLayout
                android:id="@+id/toolbar_layout"
                android:fitsSystemWindows="true"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:toolbarId="@+id/toolbar"
                app:layout_scrollFlags="scroll|exitUntilCollapsed"
                app:contentScrim="?attr/colorPrimary">

            <androidx.appcompat.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_height="?attr/actionBarSize"
                    android:layout_width="match_parent"
                    app:layout_collapseMode="pin"
                    app:popupTheme="@style/AppTheme.PopupOverlay"/>

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


The errors received:


java.lang.IllegalArgumentException: java.lang.ClassCastException@466d8fa7
    at sun.reflect.GeneratedMethodAccessor738.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at android.animation.PropertyValuesHolder_Delegate.callMethod(PropertyValuesHolder_Delegate.java:108)
    at android.animation.PropertyValuesHolder_Delegate.nCallFloatMethod(PropertyValuesHolder_Delegate.java:143)
    at android.animation.PropertyValuesHolder.nCallFloatMethod(PropertyValuesHolder.java)
    at android.animation.PropertyValuesHolder.access$400(PropertyValuesHolder.java:38)
    at android.animation.PropertyValuesHolder$FloatPropertyValuesHolder.setAnimatedValue(PropertyValuesHolder.java:1387)
    at android.animation.ObjectAnimator.animateValue(ObjectAnimator.java:990)
    at android.animation.ValueAnimator.animateBasedOnTime(ValueAnimator.java:1339)
    at android.animation.ValueAnimator.doAnimationFrame(ValueAnimator.java:1471)
    at android.animation.AnimationHandler.doAnimationFrame(AnimationHandler.java:146)
    at android.animation.AnimationHandler.access$100(AnimationHandler.java:37)
    at android.animation.AnimationHandler$1.doFrame(AnimationHandler.java:54)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:947)
    at android.view.Choreographer.doCallbacks(Choreographer.java:761)
    at android.view.Choreographer_Delegate.doFrame(Choreographer_Delegate.java:66)
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.renderAndBuildResult(RenderSessionImpl.java:563)
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.render(RenderSessionImpl.java:425)
    at com.android.layoutlib.bridge.BridgeRenderSession.render(BridgeRenderSession.java:120)
    at com.android.ide.common.rendering.api.RenderSession.render(RenderSession.java:151)
    at com.android.ide.common.rendering.api.RenderSession.render(RenderSession.java:133)
    at com.android.tools.idea.rendering.RenderTask.lambda$null$8(RenderTask.java:755)
    at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1590)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

--------------------------------------------------

java.lang.IllegalArgumentException: java.lang.ClassCastException@1ff1f72c
    at sun.reflect.GeneratedMethodAccessor738.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at android.animation.PropertyValuesHolder_Delegate.callMethod(PropertyValuesHolder_Delegate.java:108)
    at android.animation.PropertyValuesHolder_Delegate.nCallFloatMethod(PropertyValuesHolder_Delegate.java:143)
    at android.animation.PropertyValuesHolder.nCallFloatMethod(PropertyValuesHolder.java)
    at android.animation.PropertyValuesHolder.access$400(PropertyValuesHolder.java:38)
    at android.animation.PropertyValuesHolder$FloatPropertyValuesHolder.setAnimatedValue(PropertyValuesHolder.java:1387)
    at android.animation.ObjectAnimator.animateValue(ObjectAnimator.java:990)
    at android.animation.ValueAnimator.animateBasedOnTime(ValueAnimator.java:1339)
    at android.animation.ValueAnimator.doAnimationFrame(ValueAnimator.java:1471)
    at android.animation.AnimationHandler.doAnimationFrame(AnimationHandler.java:146)
    at android.animation.AnimationHandler.access$100(AnimationHandler.java:37)
    at android.animation.AnimationHandler$1.doFrame(AnimationHandler.java:54)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:947)
    at android.view.Choreographer.doCallbacks(Choreographer.java:761)
    at android.view.Choreographer_Delegate.doFrame(Choreographer_Delegate.java:66)
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.renderAndBuildResult(RenderSessionImpl.java:563)
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.render(RenderSessionImpl.java:425)
    at com.android.layoutlib.bridge.BridgeRenderSession.render(BridgeRenderSession.java:120)
    at com.android.ide.common.rendering.api.RenderSession.render(RenderSession.java:151)
    at com.android.ide.common.rendering.api.RenderSession.render(RenderSession.java:133)
    at com.android.tools.idea.rendering.RenderTask.lambda$null$8(RenderTask.java:755)
    at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1590)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

4

2 回答 2

1

这是材质组件 1.1.0-alphax 和当前稳定的 Android Studio(在我的例子中是 3.4.1)的问题。尝试回到版本 1.0.0 或下载 Android Studio 3.5 Beta-x(我的是 beta-04)。

于 2019-06-11T10:15:04.737 回答
0

我通过单击文件-> 使缓存无效暂时解决了该问题。它已经解决了一段时间的问题,但是在添加了一些约束后,约束布局问题再次出现

于 2019-05-19T10:15:30.920 回答