【问题标题】:How to use motion layout with recyclerview如何在 recyclerview 中使用运动布局
【发布时间】:2019-03-11 07:41:33
【问题描述】:

尝试将MotionLayoutRecyclerView 一起使用,

向上滚动时,app 因错误而崩溃:

android.content.res.Resources$NotFoundException: 找不到 资源 ID #0xffffffff

片段布局代码为

<android.support.constraint.motion.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"
    app:layoutDescription="@xml/collapsing_config_order_details"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    ...

<android.support.v7.widget.CardView
        android:id="@+id/cardView"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        app:layout_constraintEnd_toEndOf="@+id/tv_delivery_type"
        app:layout_constraintStart_toStartOf="@+id/imageView15"
        app:layout_constraintTop_toBottomOf="@+id/view4">

     ...

</android.support.v7.widget.CardView>

<android.support.v7.widget.RecyclerView
        android:id="@+id/rv_list"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginBottom="8dp"
        android:layout_marginTop="8dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="@+id/cardView"
        app:layout_constraintStart_toStartOf="@+id/cardView"
        app:layout_constraintTop_toBottomOf="@+id/cardView" />

</android.support.constraint.motion.MotionLayout>

而layoutDescription代码为:

<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

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

        <OnSwipe
            app:dragDirection="dragUp"
            app:touchAnchorSide="top"
            app:moveWhenScrollAtTop="@+id/rv_list" />

    </Transition>

    <ConstraintSet android:id="@+id/expanded"
            android:id="@+id/cardView"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            app:layout_constraintEnd_toEndOf="@+id/tv_delivery_type"
            app:layout_constraintStart_toStartOf="@+id/imageView15"
            app:layout_constraintTop_toBottomOf="@+id/view4" />
    </ConstraintSet>

    <ConstraintSet android:id="@+id/collapsed">
    <Constraint
            android:id="@+id/cardView"
            android:layout_width="0dp"
            android:layout_height="1dp"
            android:layout_marginTop="8dp"
            app:layout_constraintEnd_toEndOf="@+id/tv_delivery_type"
            app:layout_constraintStart_toStartOf="@+id/imageView15"
            app:layout_constraintTop_toBottomOf="@+id/view4" />
    </ConstraintSet>

</MotionScene>

【问题讨论】:

  • 您的自动生成的资源文件中是否有 id 为 0xffffffff 的资源?
  • 不,R.java中没有预设这个id

标签: android android-recyclerview scroll swipe android-motionlayout


【解决方案1】:
app:moveWhenScrollAtTop="@+id/rv_list"

app:moveWhenScrollAtTop 的值应该是布尔值。

【讨论】:

    【解决方案2】:

    android:nestedScrollingEnabled="false" 添加到您的recyclerView

    适合我。

    【讨论】:

    • 对我也有用,tks
    【解决方案3】:

    改变

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

    <ConstraintSet android:id="@+id/expanded" >
    <Constraint android:id="@+id/cardView"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            app:layout_constraintEnd_toEndOf="@+id/tv_delivery_type"
            app:layout_constraintStart_toStartOf="@+id/imageView15"
            app:layout_constraintTop_toBottomOf="@+id/view4" />
    </ConstraintSet>
    

    【讨论】:

      【解决方案4】:

      每个ConstraintSet应该有自己的Constraint,你需要指定尽可能多的Constraint来改变场景,比如如果你想通过一次交互来移动A和B,你需要指定两者合二为一ConstraintSet

      另外,我不确定你想要实现什么,但我认为你需要编写如下代码

      <OnSwipe
              app:dragDirection="dragUp"
              app:touchAnchorId="@id/rv_list"
              app:touchAnchorSide="top" />
      

      这意味着您的目标是 rv_list 来触发操作。

      【讨论】:

      • 另外,由于您已经在layout 文件中添加了viewId,您需要将android:id="@+id/cardView" 更改为android:id="@id/cardView"
      猜你喜欢
      • 2021-07-09
      • 1970-01-01
      • 2015-09-03
      • 1970-01-01
      • 2021-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多