【发布时间】: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