Android MotionLayout 在 RecyclerView 滚动时崩溃
Android MotionLayout crashes on RecyclerView scrolling
我在 MotionLayout 中有 RecyclerView
像这样(这是示例,fragment_search_menu布局中还有其他视图):
<androidx.constraintlayout.motion.widget.MotionLayout
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/fragment_search_motion"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutDescription="@xml/fragment_search_scene"
tools:showPaths="true">
<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragment_search_map"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@+id/fragment_search_spacer"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Space
android:id="@+id/fragment_search_spacer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/large_gap"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/fragment_search_menu" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/fragment_search_menu"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@drawable/background_rounded_corners_gray"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_percent="0.63"
app:layout_constraintStart_toStartOf="parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/fragment_search_menu_recycler"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.motion.widget.MotionLayout>
使用此日志滚动 recyclerview 后应用程序崩溃:
java.lang.NullPointerException: Attempt to invoke virtual method 'int android.view.View.getId()' on a null object reference
at androidx.constraintlayout.motion.widget.MotionLayout.onNestedPreScroll(MotionLayout.java:2200)
at androidx.core.view.ViewParentCompat.onNestedPreScroll(ViewParentCompat.java:386)
at androidx.core.view.NestedScrollingChildHelper.dispatchNestedPreScroll(NestedScrollingChildHelper.java:322)
at androidx.recyclerview.widget.RecyclerView.dispatchNestedPreScroll(RecyclerView.java:11595)
at androidx.recyclerview.widget.RecyclerView$ViewFlinger.run(RecyclerView.java:5286)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:966)
at android.view.Choreographer.doCallbacks(Choreographer.java:778)
at android.view.Choreographer.doFrame(Choreographer.java:710)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:952)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6518)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
我有这个版本的 ConstraintLayout(最新):androidx.constraintlayout:constraintlayout:2.0.0-beta7
而且我不知道如何处理这次崩溃
这是一个已知问题。
请改用androidx.constraintlayout:constraintlayout:2.0.0-beta6
我在 MotionLayout 中有 RecyclerView
像这样(这是示例,fragment_search_menu布局中还有其他视图):
<androidx.constraintlayout.motion.widget.MotionLayout
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/fragment_search_motion"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutDescription="@xml/fragment_search_scene"
tools:showPaths="true">
<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragment_search_map"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@+id/fragment_search_spacer"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Space
android:id="@+id/fragment_search_spacer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/large_gap"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/fragment_search_menu" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/fragment_search_menu"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@drawable/background_rounded_corners_gray"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_percent="0.63"
app:layout_constraintStart_toStartOf="parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/fragment_search_menu_recycler"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.motion.widget.MotionLayout>
使用此日志滚动 recyclerview 后应用程序崩溃:
java.lang.NullPointerException: Attempt to invoke virtual method 'int android.view.View.getId()' on a null object reference
at androidx.constraintlayout.motion.widget.MotionLayout.onNestedPreScroll(MotionLayout.java:2200)
at androidx.core.view.ViewParentCompat.onNestedPreScroll(ViewParentCompat.java:386)
at androidx.core.view.NestedScrollingChildHelper.dispatchNestedPreScroll(NestedScrollingChildHelper.java:322)
at androidx.recyclerview.widget.RecyclerView.dispatchNestedPreScroll(RecyclerView.java:11595)
at androidx.recyclerview.widget.RecyclerView$ViewFlinger.run(RecyclerView.java:5286)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:966)
at android.view.Choreographer.doCallbacks(Choreographer.java:778)
at android.view.Choreographer.doFrame(Choreographer.java:710)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:952)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6518)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
我有这个版本的 ConstraintLayout(最新):androidx.constraintlayout:constraintlayout:2.0.0-beta7
而且我不知道如何处理这次崩溃
这是一个已知问题。
请改用androidx.constraintlayout:constraintlayout:2.0.0-beta6