【问题标题】:MotionLayout with Viewpager's Recyclerview带有 Viewpager 的 Recyclerview 的 MotionLayout
【发布时间】:2020-02-22 15:19:13
【问题描述】:

我有这样的布局;

<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/motion_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:orientation="vertical"
app:layoutDescription="@xml/motion_layout_details">

<androidx.appcompat.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:background="@color/white"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:navigationIcon="@drawable/ic_back"
    app:title="ToolbarTitle" />

 <androidx.appcompat.widget.AppCompatImageView
    android:id="@+id/image"
    android:layout_width="0dp"
    android:layout_height="244dp"
    android:scaleType="fitXY" />

<com.google.android.material.tabs.TabLayout
    android:id="@+id/tl_menu"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:elevation="2dp"
    app:tabIndicator="@null"
    app:tabMode="scrollable"
    app:tabRippleColor="@null" />

<androidx.viewpager.widget.ViewPager
    android:id="@+id/vp_menu"
    android:layout_width="0dp"
    android:layout_height="0dp" />

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

具有包含recyclerview的相同viewpager项目;

<androidx.constraintlayout.widget.ConstraintLayout 
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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical"
android:paddingTop="@dimen/spacing_16dp">

<androidx.recyclerview.widget.RecyclerView
    android:id="@+id/recyclerview"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:clipToPadding="false"
    android:orientation="vertical"
    android:paddingBottom="@dimen/spacing_24dp"
    app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"/>


</androidx.constraintlayout.widget.ConstraintLayout>

我有一个向上滚动时折叠图像的运动场景(此配置是正确的)。如果在我的 viewpager 项目中,我将我的 RecyclerView 包装在一个nestedscrollview 我的转换中 -

   <Transition
    app:constraintSetEnd="@+id/end"
    app:constraintSetStart="@+id/start"
    app:duration="500"
    app:motionInterpolator="linear">

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

</Transition>

工作得很好,并且转换如我所料。但是删除嵌套的滚动视图根本不再触发运动布局。我已经挖了好几个小时,似乎找不到任何解释。我可以将nestedscrollview 放回原处,但理想情况下我想将其排除在外,因为 A) 不需要它并且 B) 破坏了我正在使用的一些 Stickheader 内容。

更新 根据我的评论修复了这个问题。 .isNestedScrollingEnabled = false 停止 recyclerview 与 motionlayout 的通信。

【问题讨论】:

  • 你有解决办法吗?

标签: android android-motionlayout


【解决方案1】:

事实证明,当我在嵌套滚动视图中使用我的 recyclerview 时,我有 rv?.isNestedScrollingEnabled = false,它必须停止某种动作布局的触发器。删除此问题已解决问题并适用于上述代码。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-16
    • 1970-01-01
    相关资源
    最近更新 更多