Resources$NotFoundException: 无法使用带 Motionlayout 的 NestedScrollView 找到资源 ID #0xffffffff

Resources$NotFoundException: Unable to find resource ID #0xffffffff using NestedScrollView with Motionlayout

当结合使用 NestedScrollViewMotionlayout 时,我得到上面的书面错误。奇怪的是,这个错误 只会发生 ,当 Nestedscrollview 中有一些项目时(Constraintlayouttextviewbuttonedittext 等)AND 当我尝试移动 NestedScrollView起来。

使用 ScrollView 解决了这个问题,但是滚动不起作用...

BaseXML(对于 MotionLayout)

<layout 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">

    <data>
        <variable
            name="product"
            type="com.example.app.framework.datasource.models.product.Product" />
    </data>

    <androidx.constraintlayout.motion.widget.MotionLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layoutDescription="@xml/shop_item_content_scene"
        app:showPaths="true"
        tools:context=".framework.ui.view.fragments.shop.ShopItemFragment">

        <com.google.android.material.appbar.MaterialToolbar
            android:id="@+id/shop_toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/ThemeOverlay.AppCompat.Light"
            app:menu="@menu/shop_item_toolbar"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <ImageView
            android:id="@+id/product_image"
            android:layout_width="0dp"
            android:layout_height="142dp"
            android:layout_marginStart="72dp"
            android:layout_marginTop="@dimen/standard8dpMargin"
            android:layout_marginEnd="72dp"
            android:adjustViewBounds="true"
            android:background="@color/color_white"
            android:contentDescription="@null"
            android:fitsSystemWindows="true"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/shop_toolbar"
            tools:src="@drawable/ic_example_logo" />

        <com.google.android.material.textview.MaterialTextView
            android:id="@+id/product_name"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/big16dpMargin"
            android:layout_marginBottom="12dp"
            android:ellipsize="end"
            android:fontFamily="sans-serif-medium"
            android:maxLines="2"
            android:text="@{product.name}"
            android:textAlignment="textStart"
            android:textColor="@color/color_text_dark"
            android:textSize="@dimen/textHeadlineNormal1"
            app:layout_constraintBottom_toTopOf="@id/scrollview_shop"
            app:layout_constraintEnd_toEndOf="@id/barrier"
            app:layout_constraintStart_toStartOf="@id/margin_left"
            app:layout_constraintTop_toBottomOf="@+id/product_image"
            tools:text="This is a long text to test ellipsize" />

        <com.google.android.material.button.MaterialButton
            android:id="@+id/btn_shop"
            style="@style/Widget.MaterialComponents.Button.Icon"
            android:layout_width="56dp"
            android:layout_height="56dp"
            android:layout_marginEnd="16dp"
            android:backgroundTint="@color/color_btn_blue"
            android:insetLeft="0dp"
            android:insetTop="0dp"
            android:insetRight="0dp"
            android:insetBottom="0dp"
            android:padding="0dp"
            app:icon="@drawable/ic_shopping_cart_filled"
            app:iconGravity="textStart"
            app:iconPadding="0dp"
            app:layout_constraintBottom_toTopOf="@id/scrollview_shop"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="@id/scrollview_shop"
            app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlay.example.Button.Circle" />

        <include
            android:id="@+id/scrollview_shop"
            layout="@layout/shop_item_scroll"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            app:prod="@{product}"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/product_name" />

        <androidx.constraintlayout.widget.Barrier
            android:id="@+id/barrier"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:barrierDirection="left"
            app:constraint_referenced_ids="btn_shop" />

        <androidx.constraintlayout.widget.Guideline
            android:id="@+id/margin_left"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            app:layout_constraintGuide_begin="@dimen/big16dpMargin" />


    </androidx.constraintlayout.motion.widget.MotionLayout>
</layout>

嵌套滚动视图XML

<?xml version="1.0" encoding="utf-8"?>
<layout 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">

    <data>
        <variable
            name="prod"
            type="com.example.app.framework.datasource.models.product.Product" />
    </data>

    <androidx.core.widget.NestedScrollView
        android:id="@+id/scrollable"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:background="@color/color_shop_item_background">

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

            <com.google.android.material.textview.MaterialTextView
                android:id="@+id/product_article_number"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/standard8dpMargin"
                android:text="FISCH123"
                android:textAlignment="textStart"
                android:textColor="@color/color_text_gray"
                android:textDirection="locale"
                android:textSize="@dimen/textDescriptionNormal2"
                android:textStyle="normal"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                tools:text="PRICE" />

            <com.google.android.material.textview.MaterialTextView
                android:id="@+id/tv_mwst_disclaimer"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/standard8dpMargin"
                android:text="SEIFE123"
                android:textAlignment="textStart"
                android:textColor="@color/color_text_mwst"
                android:textDirection="locale"
                android:textSize="@dimen/textDescriptionNormal4"
                android:textStyle="italic"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/product_article_number"
                tools:text="PRICE" />
        </androidx.constraintlayout.widget.ConstraintLayout>
    </androidx.core.widget.NestedScrollView>
</layout>

ContentScence XML

<?xml version="1.0" encoding="utf-8"?>
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:motion="http://schemas.android.com/tools">

    <Transition
        app:constraintSetEnd="@id/collapsed"
        app:constraintSetStart="@id/expanded">

        <OnSwipe
            motion:dragDirection="dragUp"
            app:onTouchUp="stop"
            motion:touchAnchorId="@id/scrollview_shop"
            motion:touchAnchorSide="top" />

        <KeyFrameSet>
            <KeyAttribute
                app:motionTarget="@id/product_image"
                app:framePosition="40"
                android:alpha="0.0" />
        </KeyFrameSet>
    </Transition>

    <ConstraintSet android:id="@+id/expanded" />

    <ConstraintSet android:id="@+id/collapsed">
        <Constraint
            android:id="@id/product_image"
            android:layout_height="?attr/actionBarSize"
            android:layout_marginStart="56dp"
            android:layout_marginEnd="56dp"
            android:alpha="0.0"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <Constraint
            android:id="@id/product_name"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="56dp"
            android:layout_marginEnd="@dimen/standard8dpMargin"
            android:scaleX="0.925"
            android:scaleY="0.925"
            app:layout_constraintBottom_toBottomOf="@id/shop_toolbar"
            app:layout_constraintTop_toTopOf="@id/shop_toolbar"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="@id/barrier" />

        <Constraint
            android:id="@id/btn_shop"
            android:layout_marginEnd="@dimen/big16dpMargin"
            android:layout_width="56dp"
            android:layout_height="56dp"
            app:layout_constraintBottom_toBottomOf="@id/shop_toolbar"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/product_name" />
    </ConstraintSet>

</MotionScene>

片段

class ShopItemFragment : Fragment(R.layout.fragment_shop_item) {
    private val productArgs by navArgs<ShopItemFragmentArgs>()

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return FragmentShopItemBinding.inflate(inflater, container, false).apply {
            product = productArgs.product
        }.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initToolbar()
    }

    private fun initToolbar() = with(shop_toolbar) {
        setupWithNavController(findNavController(), AppBarConfiguration(findNavController().graph))
    }
}

堆栈跟踪

E/com.example.ap: No package ID ff found for ID 0xffffffff.
E/InputEventReceiver: Exception dispatching input event.
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.app, PID: 17221
    android.content.res.Resources$NotFoundException: Unable to find resource ID #0xffffffff
        at android.content.res.ResourcesImpl.getResourceName(ResourcesImpl.java:276)
        at android.content.res.Resources.getResourceName(Resources.java:2064)
        at androidx.constraintlayout.motion.widget.MotionLayout.getAnchorDpDt(MotionLayout.java:3572)
        at androidx.constraintlayout.motion.widget.TouchResponse.scrollMove(TouchResponse.java:373)
        at androidx.constraintlayout.motion.widget.MotionScene.processScrollMove(MotionScene.java:1347)
        at androidx.constraintlayout.motion.widget.MotionLayout.onNestedPreScroll(MotionLayout.java:2500)
        at androidx.core.view.ViewParentCompat.onNestedPreScroll(ViewParentCompat.java:386)
        at androidx.core.view.NestedScrollingChildHelper.dispatchNestedPreScroll(NestedScrollingChildHelper.java:322)
        at androidx.core.widget.NestedScrollView.dispatchNestedPreScroll(NestedScrollView.java:254)
        at androidx.core.widget.NestedScrollView.onTouchEvent(NestedScrollView.java:888)
        at android.view.View.dispatchTouchEvent(View.java:13415)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3054)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2741)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3060)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2755)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3060)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2755)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3060)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2755)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3060)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2755)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3060)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2755)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3060)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2755)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3060)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2755)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3060)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2755)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3060)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2755)
        at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:465)
        at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1849)
        at android.app.Activity.dispatchTouchEvent(Activity.java:3993)
        at androidx.appcompat.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:69)
        at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:423)
        at android.view.View.dispatchPointerEvent(View.java:13674)
        at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:5482)
        at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:5285)
        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4788)
        at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4841)
        at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4807)
        at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4947)
        at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4815)
        at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:5004)
        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4788)
        at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4841)
        at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4807)
        at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4815)
        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4788)
        at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:7505)
        at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:7474)
        at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:7435)
        at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:7630)
        at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:188)
        at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method)
        at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:178)
        at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:7581)
        at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:7654)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:966)
        at android.view.Choreographer.doCallbacks(Choreographer.java:790)
        at android.view.Choreographer.doFrame(Choreographer.java:718)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:951)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

图片(有ScrollView,但是Scrolling不起作用)

好的,我的问题已经解决了。有两个问题:我的颜色和布局 ID。

首先,我删除了所有自定义的黑白颜色,并使用了 @android:color/white@android:color/black。其次,我给了 EVERY 布局(constraintlayout、我的 motionlayouttextview 等)自定义 ID。

滚动行为现在有效,我遇到的唯一问题是,我得到 W/MotionLayout: WARNING could not find view id -1 并且滚动真的很慢。将为此错误打开