简体   繁体   English

MotionLayout 与 Viewpager 的 Recyclerview

[英]MotionLayout with Viewpager's Recyclerview

I have a layout as such;我有这样的布局;

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

With identical viewpager items that contain a recyclerview;使用包含 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>

I have a motion scene that collapses the image when scrolled up (the configurations for this are correct).我有一个运动场景,向上滚动时会折叠图像(此配置是正确的)。 If in my viewpager items I wrap my RecyclerView in a nestedscrollview my transition -如果在我的 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>

Works just fine, and transitions as I'd expect.工作正常,并且按照我的预期进行转换。 But removing that nested scrollview no longer triggers the motion layout at all.但是删除嵌套的滚动视图根本不再触发运动布局。 I've dug around for a good couple of hours and can't seem to find any explanation.我已经挖了好几个小时,似乎找不到任何解释。 I could put the nestedscrollview back in, but ideally I'd like to leave it out as A) it's not needed and B) breaks some stickheader stuff I'm using.我可以将 nestedscrollview 放回去,但理想情况下我想将其保留下来,因为 A) 不需要它并且 B) 破坏了我正在使用的一些 stickheader 东西。

UPDATE Fixed this as per my comment.更新根据我的评论解决了这个问题。 .isNestedScrollingEnabled = false stops the recyclerview communicating with the motionlayout. .isNestedScrollingEnabled = false停止 recyclerview 与 motionlayout 的通信。

Turns out, from when I had my recyclerview in a nestedscrollview I had rv?.isNestedScrollingEnabled = false which must be stopping some kind of trigger for the motionlayout.事实证明,当我在 nestedscrollview 中使用我的 recyclerview 时,我有rv?.isNestedScrollingEnabled = false ,它必须停止某种类型的 motionlayout 触发器。 Removing this has fixed the issue and works with the above code.删除它可以解决问题并使用上面的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM