如何解决MotionLayout和NestedScrollView RecylerView滚动问题
我在将recyclerview滚动到水平方向时遇到意外动画动画的问题。回收者视图在NestedScrollView内部,而NestedScrollView在MotionLayout内部。我花了几天时间才找到原因,但没有成功,请帮助
<?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="viewModel"
type="com.aaa.viewModel.preview.PreviewVM" />
</data>
<androidx.constraintlayout.motion.widget.MotionLayout
android:id="@+id/motionLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/gray_3"
android:clickable="true"
android:focusable="true"
app:layoutDescription="@xml/motion_scene"
app:showPaths="false">
<ImageView
android:id="@+id/imageContainer"
android:layout_width="@dimen/_85sdp"
android:layout_height="@dimen/_85sdp"
android:layout_gravity="center"
android:layout_marginStart="@dimen/_8sdp"
android:layout_marginTop="@dimen/_4sdp"
android:contentDescription="@string/todo"
android:scaleType="centerCrop"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:src="@{viewModel.itemAlbum.avatarUrl}" />
<RelativeLayout
android:id="@+id/container"
android:layout_width="0dp"
android:layout_height="@dimen/_100sdp"
android:layout_marginStart="@dimen/_8sdp"
android:layout_marginEnd="@dimen/_8sdp"
app:layout_constraintBottom_toTopOf="@+id/space"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/imageContainer">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_12sdp"
android:ellipsize="marquee"
android:fontFamily="@font/gotham_book"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="Title"
android:textColor="@color/FC_BACKGROUND_COLOR"
android:textSize="@dimen/_13sdp"
tools:text="Cantigo" />
<Button
android:layout_width="match_parent"
android:layout_height="@dimen/_30sdp"
android:layout_alignParentBottom="true"
android:background="@drawable/rounded_black_5_sdp"
android:backgroundTint="@color/FC_SECONDARY_COLOR"
android:fontFamily="@font/gotham_bold"
android:gravity="center"
android:text="Button"
android:textColor="@color/black"
android:textSize="@dimen/_12sdp" />
</RelativeLayout>
<androidx.core.widget.NestedScrollView
android:id="@+id/nestedScrollView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="@dimen/_4sdp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageContainer">
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:orientation="vertical">
<View
android:id="@+id/adView"
android:layout_width="300dp"
android:layout_height="250dp"
android:layout_gravity="center"
android:layout_marginTop="@dimen/_18sdp"
android:layout_marginBottom="@dimen/_14sdp"
android:background="@color/coin_tutorial_bg" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvArtistAlbum"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tvAlbum"
android:layout_marginTop="@dimen/_5sdp"
android:background="@color/app_background"
android:nestedScrollingEnabled="false"
android:orientation="horizontal"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvArtist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tvAlbum"
android:layout_marginTop="@dimen/_25sdp"
android:background="@color/app_background"
android:nestedScrollingEnabled="false"
android:orientation="horizontal"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
</androidx.appcompat.widget.LinearLayoutCompat>
</androidx.core.widget.NestedScrollView>
<Space
android:id="@+id/space"
android:layout_width="0dp"
android:layout_height="@dimen/_8sdp"
app:layout_constraintEnd_toEndOf="@+id/imageContainer"
app:layout_constraintStart_toEndOf="@+id/imageContainer"
app:layout_constraintStart_toStartOf="@+id/imageContainer"
app:layout_constraintTop_toBottomOf="@id/imageContainer" />
</androidx.constraintlayout.motion.widget.MotionLayout>
</layout>
解决方法
我认为您不希望滑动和nestedScrollView(RecyclerView)进行交互 在您添加
motion:nestedScrollFlags =“ disableScroll”
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。