Search code examples
androidandroid-studioandroidx

How to solve a render problem in Android Studio?


I use AndroidX library and I have a rendering problem in my XML file. It happens only in one XML. This is the single activity layout that I used Material widgets, therefore, I think It can be a reason.

My XML code is here:

<?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>

The error message shows it:

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)

I faced this error before, but when I changed the version of the ConstraintLayout implementation, I solved the problem, but this one is something else.

My implementation:

implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

Solution

  • I found the problem. I post it, maybe somebody will need it. AppBarLayout causes a rendering problem. I cannot find why it causes an error, but I think It is an Android X's bug. It works fine in AppCompat V7. I found an alternative way.