二进制 XML 文件第 35 行:错误膨胀类 androidx.viewpager2.widget.ViewPager2

时间:2021-07-26 13:40:24

标签: android android-viewpager2

我想在我的项目中使用 viewpager2,但应用程序崩溃了。下面是 XML 代码:

<块引用>

二进制 XML 文件第 35 行:错误增加类 androidx.viewpager2.widget.ViewPager2

<块引用>

Caused by: java.lang.IllegalArgumentException: 不支持向 RecyclerView 提供 LayoutTransition。

<块引用>

我知道这个问题可以通过设置 android:animateLayoutChanges="false"

在 Recyclerview 中解决
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:animateLayoutChanges="true"
    tools:context="in.kskt.happykitchen.view.activity.SplashActivity">

    <androidx.appcompat.widget.AppCompatImageView
        android:layout_width="@dimen/_144sdp"
        android:layout_height="@dimen/_144sdp"
        android:src="@drawable/kskt_logo"
        android:layout_marginBottom="@dimen/_64sdp"
        android:layout_marginRight="@dimen/_8sdp"
        android:transitionName="logo"
        android:id="@+id/img_logo"
        android:layout_gravity="center|center_horizontal"/>


    <ProgressBar
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center|bottom"
        android:layout_marginBottom="@dimen/_64sdp"/>

    <androidx.viewpager2.widget.ViewPager2
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/viewpager"/>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

和崩溃报告如下:

Caused by: android.view.InflateException: Binary XML file line #35: Error inflating class androidx.viewpager2.widget.ViewPager2
    at android.view.LayoutInflater.createView(LayoutInflater.java:633)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
    at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:699)
    at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:195)
    at androidx.databinding.DataBindingUtil.setContentView(DataBindingUtil.java:303)
    at androidx.databinding.DataBindingUtil.setContentView(DataBindingUtil.java:284)
    at in.com.kskt.ui.base.BaseActivity.onCreate(BaseActivity.java:36)
    at in.com.kskt.ui.splash.SplashActivity.onCreate(SplashActivity.java:19)
    at android.app.Activity.performCreate(Activity.java:6010)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1129)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2292)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2413) 
    at android.app.ActivityThread.access$800(ActivityThread.java:155) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1317) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:135) 
    at android.app.ActivityThread.main(ActivityThread.java:5343) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:372) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700) 
 Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Constructor.newInstance(Native Method)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
    at android.view.LayoutInflater.createView(LayoutInflater.java:607)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743) 
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:504) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:414) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:365) 
    at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:699) 
    at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:195) 
    at androidx.databinding.DataBindingUtil.setContentView(DataBindingUtil.java:303) 
    at androidx.databinding.DataBindingUtil.setContentView(DataBindingUtil.java:284) 
    at in.com.kskt.ui.base.BaseActivity.onCreate(BaseActivity.java:36) 
    at in.com.kskt.ui.splash.SplashActivity.onCreate(SplashActivity.java:19) 
    at android.app.Activity.performCreate(Activity.java:6010) 
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1129) 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2292) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2413) 
    at android.app.ActivityThread.access$800(ActivityThread.java:155) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1317) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:135) 
    at android.app.ActivityThread.main(ActivityThread.java:5343) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:372) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700) 
 Caused by: java.lang.IllegalArgumentException: Providing a LayoutTransition into RecyclerView is not supported. Please use setItemAnimator() instead for animating changes to the items in this RecyclerView
    at androidx.recyclerview.widget.RecyclerView.setLayoutTransition(RecyclerView.java:2442)
    at android.view.ViewGroup.initFromAttributes(ViewGroup.java:571)
    at android.view.ViewGroup.<init>(ViewGroup.java:499)
    at android.view.ViewGroup.<init>(ViewGroup.java:493)
    at androidx.recyclerview.widget.RecyclerView.<init>(RecyclerView.java:689)
    at androidx.recyclerview.widget.RecyclerView.<init>(RecyclerView.java:685)
    at androidx.recyclerview.widget.RecyclerView.<init>(RecyclerView.java:681)
    at androidx.viewpager2.widget.ViewPager2$RecyclerViewImpl.<init>(ViewPager2.java:968)
    at androidx.viewpager2.widget.ViewPager2.initialize(ViewPager2.java:183)
    at androidx.viewpager2.widget.ViewPager2.<init>(ViewPager2.java:163)
    at java.lang.reflect.Constructor.newInstance(Native Method) 
    at java.lang.reflect.Constructor.newInstance(Constructor.java:288) 
    at android.view.LayoutInflater.createView(LayoutInflater.java:607) 
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743) 
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:504) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:414) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:365) 
    at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:699) 
    at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:195) 
    at androidx.databinding.DataBindingUtil.setContentView(DataBindingUtil.java:303) 
    at androidx.databinding.DataBindingUtil.setContentView(DataBindingUtil.java:284) 
    at in.com.kskt.ui.base.BaseActivity.onCreate(BaseActivity.java:36) 
    at in.com.kskt.ui.splash.SplashActivity.onCreate(SplashActivity.java:19) 
    at android.app.Activity.performCreate(Activity.java:6010) 
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1129) 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2292) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2413) 
    at android.app.ActivityThread.access$800(ActivityThread.java:155) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1317) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:135) 
    at android.app.ActivityThread.main(ActivityThread.java:5343) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:372) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700) 

任何帮助将不胜感激。

0 个答案:

没有答案