如何解决新的Android Studio版本(androidx)中的渲染问题?

时间:2019-07-01 20:07:34

标签: android android-studio navigation-drawer render androidx

我将android studio更新到了最新版本,并创建了一个新项目,并添加了一个导航抽屉,但是预览在某些布局下无法正常工作。显示了一些渲染问题。

我已经将“ Theme.AppCompat.Light.DarkActionBar”更改为“ Base.Theme.AppCompat.Light.DarkActionBar”,并尝试降级API,但未进行任何更改。

<androidx.drawerlayout.widget.DrawerLayout 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/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <include
        layout="@layout/app_bar_navigation_drawer"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <com.google.android.material.navigation.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_navigation_drawer"
        app:menu="@menu/activity_navigation_drawer_drawer" />

</androidx.drawerlayout.widget.DrawerLayout>

java.lang.IllegalArgumentException: java.lang.ClassCastException@682acdca   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:-1)   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.setCurrentFraction(ValueAnimator.java:674)   at android.animation.ValueAnimator.setCurrentPlayTime(ValueAnimator.java:637)   at android.animation.ValueAnimator.start(ValueAnimator.java:1069)   at android.animation.ValueAnimator.start(ValueAnimator.java:1088)   at android.animation.ObjectAnimator.start(ObjectAnimator.java:852)   at android.animation.StateListAnimator.start(StateListAnimator.java:188)   at android.animation.StateListAnimator.setState(StateListAnimator.java:181)   at android.view.View.drawableStateChanged(View.java:21105)   at android.view.ViewGroup.drawableStateChanged(ViewGroup.java:7101)   at com.google.android.material.appbar.AppBarLayout.drawableStateChanged   ... (AppBarLayout.java:393)   at android.view.View.refreshDrawableState(View.java:21160)   at android.view.View.dispatchAttachedToWindow(View.java:18379)   at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3397)   at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3404)   at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3404)   at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3404)   at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3404)   at android.view.AttachInfo_Accessor.setAttachInfo(AttachInfo_Accessor.java:42)

2 个答案:

答案 0 :(得分:0)

https://developer.android.com/jetpack/androidx/migrate 通过上面的链接,然后按照步骤进行。使用androidx布局更改布局。

答案 1 :(得分:0)

我也面临着同样的问题。 Android版本3.4.2。清除缓存并不能解决问题。唯一的解决方法是关闭android studio并重新启动。以后再发生几次。