如何解决Android Studio中的渲染问题?

时间:2019-06-27 08:21:38

标签: android android-studio androidx

我使用AndroidX库,并且XML文件中存在渲染问题。它仅在一种XML中发生。这是我使用Material窗口小部件的单一活动布局,因此,我认为这可能是一个原因。

我的XML代码在这里:

<?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"
tools:context=".HomePage">


<com.google.android.material.bottomnavigation.BottomNavigationView
    android:id="@+id/bottom_navigation"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:background="#FFFFFF"
    app:elevation="0dp"
    app:itemIconSize="@dimen/iconBottom"
    app:itemIconTint="@drawable/bottom_nav_color"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent"
    app:menu="@menu/bottom_navigation_menu" />

<com.google.android.material.floatingactionbutton.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="65dp"
    android:layout_height="65dp"
    android:layout_above="@id/bottom_navigation"
    android:layout_alignParentBottom="true"
    android:layout_gravity="bottom|center"
    android:layout_marginStart="7dp"
    android:layout_marginBottom="20dp"
    android:backgroundTint="@android:color/transparent"
    android:onClick="OpenCamera"
    android:src="@drawable/scan"
    android:translationZ="0dp"
    app:borderWidth="0dp"
    app:elevation="0dp"
    app:maxImageSize="64dp" />


<com.google.android.material.appbar.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="345dp"
    android:backgroundTint="#00F0ECEC">


    <com.google.android.material.appbar.CollapsingToolbarLayout
        android:id="@+id/collapsingtool"
        android:layout_width="match_parent"
        android:layout_height="354dp"
        android:background="#FFFFFF"
        app:collapsedTitleGravity="top|center"
        app:contentScrim="#FFFFFF"
        app:layout_scrollFlags="scroll|enterAlwaysCollapsed|snap"
        app:titleEnabled="false">


        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ImageView
                android:id="@+id/BackImage"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:scaleType="centerCrop"
                android:tint="#6F000000"
                app:layout_constraintBottom_toBottomOf="@+id/textView"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                tools:srcCompat="@tools:sample/avatars" />


            <ImageView
                android:id="@+id/imageView"
                android:layout_width="659dp"
                android:layout_height="641dp"
                android:layout_marginEnd="8dp"
                android:layout_marginBottom="8dp"
                android:background="#00F7F7F7"
                android:visibility="invisible"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="@+id/amount"
                app:layout_constraintHorizontal_bias="0.461"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintVertical_bias="0.823"
                app:srcCompat="@drawable/ppback" />

            <de.hdodenhof.circleimageview.CircleImageView
                android:id="@+id/profilimage"
                android:layout_width="0dp"
                android:layout_height="170dp"
                android:padding="5dp"
                android:src="@drawable/unknown"
                app:civ_border_color="#FFFFFF"
                app:civ_border_width="7dp"
                app:layout_constraintEnd_toEndOf="@+id/fullname"
                app:layout_constraintStart_toStartOf="@+id/fullname"
                app:layout_constraintTop_toBottomOf="@+id/fullname"
                tools:srcCompat="@tools:sample/avatars" />

            <TextView
                android:id="@+id/fullname"
                android:layout_width="0dp"
                android:layout_height="48dp"
                android:layout_marginStart="8dp"
                android:layout_marginEnd="8dp"
                android:layout_marginBottom="8dp"
                android:fontFamily="sans-serif"
                android:lineSpacingExtra="8sp"
                android:text="Tuncay Huseynov"
                android:textAlignment="center"
                android:textAllCaps="true"
                android:textColor="@color/white"
                android:textSize="25sp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="1.0"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintVertical_bias="0.25" />

            <TextView
                android:id="@+id/textView"
                android:layout_width="130dp"
                android:layout_height="50dp"
                android:layout_marginStart="1dp"
                android:layout_marginTop="8dp"
                android:layout_marginEnd="8dp"
                android:fontFamily="@font/baloo"
                android:text="Bonus:"
                android:textAlignment="center"
                android:textAllCaps="true"
                android:textColor="#FFFFFF"
                android:textSize="30sp"
                android:textStyle="bold"
                app:layout_constraintEnd_toEndOf="@+id/profilimage"
                app:layout_constraintHorizontal_bias="0.436"
                app:layout_constraintStart_toStartOf="@+id/profilimage"
               app:layout_constraintTop_toBottomOf="@+id/profilimage"/>

            <TextView
                android:id="@+id/amount"
                android:layout_width="120dp"
                android:layout_height="51dp"
                android:fontFamily="@font/baloo"
                android:text="50"
                android:textAlignment="textStart"
                android:textColor="#FFFFFF"
                android:textSize="30sp"
                android:textStyle="bold"
                app:layout_constraintStart_toEndOf="@+id/textView"
                app:layout_constraintTop_toTopOf="@+id/textView" />

        </androidx.constraintlayout.widget.ConstraintLayout>

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/mToolbar"
            android:layout_width="match_parent"
            android:layout_height="49dp"
            android:background="#FFFFFF"
            app:layout_collapseMode="parallax"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:titleTextAppearance="@style/Toolbar.TitleText">


            <ImageButton
                android:id="@+id/map"
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:layout_gravity="start"
                android:background="@drawable/loc"
                android:text="Button" />

            <TextView
                android:id="@+id/toolbar_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:text="Ana Səhfə"
                android:textColor="@color/colorAccent"
                android:textSize="22sp"
                android:visibility="invisible" />

            <ImageButton
                android:id="@+id/setting"
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:layout_gravity="end"
                android:layout_marginRight="10dp"
                android:background="@drawable/sett"
                android:src="@drawable/sett"
                android:text="Button" />
        </androidx.appcompat.widget.Toolbar>


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

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

  <androidx.core.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipToPadding="false"
    android:translationZ="-1dp"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <include layout="@layout/main_menu_bar" />
</androidx.core.widget.NestedScrollView>

<ProgressBar
    android:id="@+id/progressBar3"
    android:layout_width="match_parent"
    android:layout_height="396dp"
    android:indeterminateDrawable="@drawable/progress"
    android:visibility="visible" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

错误消息显示它:

java.lang.IllegalArgumentException: java.lang.ClassCastException@6623a4b7
at sun.reflect.GeneratedMethodAccessor1205.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.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.ValueAnimator.startWithoutPulsing(ValueAnimator.java:1081)
at android.animation.AnimatorSet.handleAnimationEvents(AnimatorSet.java:1142)
at android.animation.AnimatorSet.startAnimation(AnimatorSet.java:1227)
at android.animation.AnimatorSet.start(AnimatorSet.java:729)
at android.animation.AnimatorSet.start(AnimatorSet.java:684)
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.widget.ImageView.drawableStateChanged(ImageView.java:1294)
at com.google.android.material.floatingactionbutton.FloatingActionButton.drawableStateChanged(FloatingActionButton.java:809)
at android.view.View.refreshDrawableState(View.java:21160)
at android.view.View.dispatchAttachedToWindow(View.java:18379)
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)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:335)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:391)
at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:195)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:540)
at com.android.tools.idea.rendering.RenderTask.lambda$inflate$5(RenderTask.java:666)
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)

我以前遇到过此错误,但是当我更改ConstraintLayout实现的版本时,我解决了问题,但这是另外一回事。

我的实现:

implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

1 个答案:

答案 0 :(得分:0)

我发现了问题。我发布它,也许有人会需要它。 AppBarLayout导致呈现问题。我找不到导致错误的原因,但我认为这是Android X的错误。在AppCompat V7中可以正常工作。我找到了另一种方法。