MotionLayout 正在进行时视图操作不起作用

kau*_*v07 5 android android-layout android-motionlayout

我正在尝试创建一个布局,其中视图将向上滚动,但在视图内有一个组件不应滚动到视图之外并停靠在顶部,其余内容滚动到其下方,该组件将滚动直到它击中屏幕顶部。

\n\n

因此,对于对接部分,我使用了运动布局,并将其限制在最终状态下的父级顶部。我在停靠的组件后面放置了一个嵌套的滚动视图。这是我的运动场景文件 -

\n\n

\n\n

<Transition\n    android:id="@+id/scrollTransition"\n    motion:constraintSetEnd="@+id/end"\n    motion:constraintSetStart="@id/start"\n    motion:duration="1000">\n   <KeyFrameSet>\n   </KeyFrameSet>\n    <OnSwipe\n        motion:dragDirection="dragUp"\n        motion:onTouchUp="stop"\n        motion:touchAnchorId="@id/merchant_details"\n        motion:moveWhenScrollAtTop="true"/>\n</Transition>\n\n<ConstraintSet android:id="@+id/start">\n\n</ConstraintSet>\n\n<ConstraintSet android:id="@+id/end">\n    <Constraint\n        android:layout_height="wrap_content"\n        motion:layout_constraintStart_toStartOf="parent"\n        motion:layout_constraintEnd_toEndOf="parent"\n        motion:layout_constraintBottom_toTopOf="@id/merchant_details"\n        android:layout_width="match_parent"\n        android:id="@+id/product_details" />\n    <Constraint\n        android:layout_height="wrap_content"\n        motion:layout_constraintStart_toStartOf="parent"\n        motion:layout_constraintEnd_toEndOf="parent"\n        motion:layout_constraintTop_toTopOf="parent"\n        android:layout_width="match_parent"\n        android:id="@+id/merchant_details" />\n</ConstraintSet>\n
Run Code Online (Sandbox Code Playgroud)\n\n

\n\n

但它应该给出它正在自然滚动的提要,并且如果用户在运动状态中间停止滚动,所以我为此添加了motion:onTouchUp="stop"

\n\n

这是我的布局文件 -

\n\n
<?xml version="1.0" encoding="utf-8"?>\n<androidx.constraintlayout.motion.widget.MotionLayout xmlns:android="http://schemas.android.com/apk/res/android"\n    xmlns:app="http://schemas.android.com/apk/res-auto"\n    xmlns:tools="http://schemas.android.com/tools"\n    xmlns:aapt="http://schemas.android.com/aapt"\n    android:id="@+id/hsmerchantListingRoot"\n    android:layout_width="match_parent"\n    android:layout_height="match_parent"\n    app:layoutDescription="@xml/activity_home_services_merchant_listing_scene"\n    tools:context="com.nearbuy.nearbuymobile.modules.home_services.HomeServicesMerchantListingActivity">\n\n    <androidx.constraintlayout.widget.ConstraintLayout\n        android:id="@+id/product_details"\n        android:layout_width="match_parent"\n        android:layout_height="wrap_content"\n        android:paddingBottom="@dimen/dp_15"\n        android:visibility="visible"\n        app:layout_constraintEnd_toEndOf="parent"\n        app:layout_constraintStart_toStartOf="parent"\n        app:layout_constraintTop_toTopOf="parent"\n        tools:visibility="gone">\n\n        <com.nearbuy.nearbuymobile.view.infiniteRotationView.InfiniteRotationView\n            android:id="@+id/productImageCarousel"\n            android:layout_width="match_parent"\n            android:layout_height="wrap_content"\n            app:layout_constraintEnd_toEndOf="parent"\n            app:layout_constraintStart_toStartOf="parent"\n            app:layout_constraintTop_toTopOf="parent" />\n\n        <WebView\n            android:id="@+id/htmlView"\n            android:layout_width="match_parent"\n            android:layout_height="wrap_content"\n            android:visibility="gone"\n            app:layout_constraintEnd_toEndOf="parent"\n            app:layout_constraintStart_toStartOf="parent"\n            app:layout_constraintTop_toBottomOf="@+id/productImageCarousel" />\n\n        <com.nearbuy.nearbuymobile.view.NB_TextView\n            android:id="@+id/detailTitle"\n            style="@style/title_3_b"\n            android:layout_width="0dp"\n            android:layout_height="wrap_content"\n            android:layout_marginStart="15dp"\n            android:layout_marginTop="15dp"\n            android:layout_marginEnd="15dp"\n            android:textColor="#2b2f31"\n            app:layout_constraintEnd_toEndOf="parent"\n            app:layout_constraintStart_toStartOf="parent"\n            app:layout_constraintTop_toBottomOf="@+id/productImageCarousel"\n            tools:text="Sofa Cleaning" />\n\n        <com.nearbuy.nearbuymobile.view.NB_TextView\n            android:id="@+id/detailDescription"\n            style="@style/body_2_r"\n            android:layout_width="0dp"\n            android:layout_height="wrap_content"\n            android:layout_marginStart="15dp"\n            android:layout_marginTop="8dp"\n            android:layout_marginEnd="15dp"\n            android:lineSpacingExtra="4.7sp"\n            android:textColor="@color/grey_n"\n            app:layout_constraintEnd_toEndOf="parent"\n            app:layout_constraintStart_toStartOf="parent"\n            app:layout_constraintTop_toBottomOf="@+id/detailTitle"\n            tools:text="From cotton upholstery to leather finish, there exists a wide array of sofa designs with a range of materials. All of them pick some amount of dust on a daily basis which cannot be washed away\xe2\x80\xa6" />\n\n        <com.nearbuy.nearbuymobile.view.NB_TextView\n            android:id="@+id/readMoreText"\n            style="@style/body_1_m"\n            android:layout_width="wrap_content"\n            android:layout_height="wrap_content"\n            android:layout_marginTop="4.7dp"\n            android:text="Read more"\n            android:textColor="@color/delight"\n            android:visibility="gone"\n            app:layout_constraintStart_toStartOf="@+id/detailDescription"\n            app:layout_constraintTop_toBottomOf="@+id/detailDescription" />\n\n        <androidx.constraintlayout.widget.Barrier\n            android:id="@+id/bannerBarrier"\n            android:layout_width="wrap_content"\n            android:layout_height="wrap_content"\n            app:barrierDirection="bottom"\n            app:constraint_referenced_ids="detailDescription,productImageCarousel,htmlView,detailTitle,readMoreText" />\n\n        <ImageView\n            android:id="@+id/serviceInfoBanner1"\n            android:layout_width="match_parent"\n            android:layout_height="wrap_content"\n            android:scaleType="fitXY"\n            android:adjustViewBounds="true"\n            app:layout_constraintStart_toStartOf="parent"\n            app:layout_constraintEnd_toEndOf="parent"\n            app:layout_constraintTop_toBottomOf="@id/bannerBarrier"\n            tools:src="@drawable/test_img1"/>\n\n        <ImageView\n            android:id="@+id/serviceInfoBanner2"\n            android:layout_width="match_parent"\n            android:layout_height="wrap_content"\n            android:scaleType="fitXY"\n            android:adjustViewBounds="true"\n            app:layout_constraintStart_toStartOf="parent"\n            app:layout_constraintEnd_toEndOf="parent"\n            app:layout_constraintTop_toBottomOf="@id/serviceInfoBanner1"\n            tools:src="@drawable/test_img1"/>\n\n    </androidx.constraintlayout.widget.ConstraintLayout>\n\n    <androidx.constraintlayout.widget.ConstraintLayout\n        android:id="@+id/merchant_details"\n        android:layout_width="match_parent"\n        android:layout_height="wrap_content"\n        app:layout_constraintBottom_toBottomOf="parent"\n        app:layout_constraintEnd_toEndOf="parent"\n        app:layout_constraintStart_toStartOf="parent"\n        app:layout_constraintTop_toBottomOf="@+id/product_details"\n        app:layout_constraintVertical_bias="0.0"\n        tools:visibility="visible">\n\n        <androidx.constraintlayout.widget.Barrier\n            android:id="@+id/dateFilterBarrier"\n            android:layout_width="wrap_content"\n            android:layout_height="wrap_content"\n            app:barrierDirection="bottom"\n            app:constraint_referenced_ids="llDateFilter" />\n\n\n        <LinearLayout\n            android:id="@+id/llDateFilter"\n            android:layout_width="match_parent"\n            android:layout_height="wrap_content"\n            android:background="#f7f7fd"\n            android:clipToPadding="false"\n            android:gravity="center_vertical"\n            android:orientation="horizontal"\n            android:paddingTop="@dimen/dp_15"\n            android:paddingBottom="@dimen/dp_10"\n            android:visibility="gone"\n            app:layout_constraintEnd_toEndOf="parent"\n            app:layout_constraintStart_toStartOf="parent"\n            app:layout_constraintTop_toTopOf="parent"\n            tools:visibility="visible">\n\n            <androidx.cardview.widget.CardView\n                android:id="@+id/cvMainFilter"\n                android:layout_width="wrap_content"\n                android:layout_height="wrap_content"\n                android:layout_marginStart="@dimen/dp_15"\n                app:cardCornerRadius="@dimen/dp_4"\n                app:cardElevation="@dimen/dp_2">\n\n                <RelativeLayout\n                    android:id="@+id/rlDate"\n                    android:layout_width="wrap_content"\n                    android:layout_height="wrap_content"\n                    android:background="@drawable/rounded_corner_gradient_blue"\n                    android:paddingStart="@dimen/dp_10"\n                    android:paddingTop="@dimen/dp_6"\n                    android:paddingEnd="@dimen/dp_10"\n                    android:paddingBottom="@dimen/dp_6">\n\n                    <com.nearbuy.nearbuymobile.view.NB_TextView\n                        android:id="@+id/tvDateTitle"\n                        style="@style/small_m"\n                        android:layout_width="wrap_content"\n                        android:layout_height="wrap_content"\n                        android:textColor="@color/white"\n                        tools:text="Today" />\n\n                    <com.nearbuy.nearbuymobile.view.NB_TextView\n                        android:id="@+id/tvDateSubtitle"\n                        style="@style/title_3_m"\n                        android:layout_width="wrap_content"\n                        android:layout_height="wrap_content"\n                        android:layout_below="@+id/tvDateTitle"\n                        android:layout_marginTop="@dimen/dp_2"\n                        android:textColor="@color/white"\n                        android:visibility="gone"\n                        tools:text="1 Oct" />\n\n                    <ImageView\n                        android:id="@+id/ivDateDownArrow"\n                        android:layout_width="wrap_content"\n                        android:layout_height="wrap_content"\n                        android:layout_below="@+id/tvDateTitle"\n                        android:layout_marginStart="@dimen/dp_10"\n                        android:layout_marginTop="@dimen/dp_10"\n                        android:layout_toEndOf="@+id/tvDateSubtitle"\n                        android:src="@drawable/arrow_down_white"\n                        android:visibility="gone" />\n\n                    <com.nearbuy.nearbuymobile.view.NB_TextView\n                        android:id="@+id/tvCount"\n                        style="@style/body_4_m"\n                        android:layout_width="wrap_content"\n                        android:layout_height="wrap_content"\n                        android:layout_centerInParent="true"\n                        android:layout_marginLeft="@dimen/dp_10"\n                        android:layout_toRightOf="@+id/tvDateTitle"\n                        android:background="@drawable/white_circle"\n                        android:gravity="center"\n                        android:paddingLeft="@dimen/dp_8"\n                        android:paddingTop="@dimen/dp_5"\n                        android:paddingRight="@dimen/dp_8"\n                        android:paddingBottom="@dimen/dp_5"\n                        android:textColor="@color/delight"\n                        android:visibility="gone"\n                        tools:text="8" />\n\n                </RelativeLayout>\n\n            </androidx.cardview.widget.CardView>\n\n            <androidx.recyclerview.widget.RecyclerView\n                android:id="@+id/rvTimeSlots"\n                android:layout_width="match_parent"\n                android:layout_height="wrap_content"\n                android:clipToPadding="false"\n                android:orientation="horizontal"\n                android:overScrollMode="never"\n                android:paddingStart="@dimen/dp_6"\n                android:paddingEnd="10dp"\n                android:scrollbars="none"\n                app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />\n\n        </LinearLayout>\n\n        <androidx.core.widget.NestedScrollView\n            android:id="@+id/merchantDetailScrollView"\n            android:layout_width="match_parent"\n            android:layout_height="wrap_content"\n            android:clipChildren="false"\n            android:clipToPadding="false"\n            android:visibility="gone"\n            app:layout_constraintBottom_toBottomOf="parent"\n            app:layout_constraintEnd_toEndOf="parent"\n            app:layout_constraintStart_toStartOf="parent"\n            app:layout_constraintTop_toBottomOf="@id/dateFilterBarrier"\n            app:layout_constraintVertical_bias="0.0"\n            tools:visibility="visible">\n\n            <LinearLayout\n                android:id="@+id/l1"\n                android:layout_width="match_parent"\n                android:layout_height="wrap_content"\n                android:orientation="vertical">\n\n                <include\n                    layout="@layout/home_services_selected_merchant_card"\n                    tools:visibility="gone" />\n\n                <ImageView\n                    android:id="@+id/merchantInfoBanner"\n                    android:layout_width="match_parent"\n                    android:layout_height="wrap_content"\n                    android:adjustViewBounds="true"\n                    android:scaleType="fitXY"\n                    tools:src="@drawable/test_img1"\n                    tools:visibility="visible" />\n\n                <androidx.constraintlayout.widget.ConstraintLayout\n                    android:id="@+id/merchantAdditionalInfoTabLayout"\n                    android:layout_marginTop="@dimen/dp_15"\n                    android:layout_width="match_parent"\n                    android:layout_height="wrap_content">\n\n                    <com.google.android.material.tabs.TabLayout\n                        android:id="@+id/merchantInfoTab"\n                        android:layout_width="0dp"\n                        android:layout_height="30dp"\n                        android:background="@color/white"\n                        app:layout_constraintEnd_toEndOf="parent"\n                        app:layout_constraintStart_toStartOf="parent"\n                        app:layout_constraintTop_toTopOf="parent"\n                        app:tabIndicatorColor="@color/delight"\n                        app:tabIndicatorHeight="@dimen/dp_2" />\n\n                    <com.nearbuy.nearbuymobile.view.CustomViewPager\n                        android:id="@+id/merchantInfoTabPager"\n                        android:layout_width="0dp"\n                        android:layout_height="wrap_content"\n                        app:layout_constraintEnd_toEndOf="parent"\n                        app:layout_constraintStart_toStartOf="parent"\n                        app:layout_constraintTop_toBottomOf="@+id/merchantInfoTab" />\n\n                </androidx.constraintlayout.widget.ConstraintLayout>\n\n\n            </LinearLayout>\n\n        </androidx.core.widget.NestedScrollView>\n\n    </androidx.constraintlayout.widget.ConstraintLayout>\n\n    <androidx.constraintlayout.widget.ConstraintLayout\n        android:id="@+id/retryLayout"\n        android:layout_width="match_parent"\n        android:layout_height="@dimen/dp_60"\n        android:background="@color/cb_verify_color"\n        android:visibility="gone"\n        app:layout_constraintTop_toBottomOf="@+id/product_details" />\n\n    <androidx.constraintlayout.widget.ConstraintLayout\n        android:id="@+id/bottomCTACard"\n        android:layout_width="match_parent"\n        android:layout_height="wrap_content"\n        android:background="@color/white"\n        android:elevation="@dimen/dp_30"\n        android:translationZ="@dimen/dp_10"\n        app:layout_constraintStart_toStartOf="parent"\n        app:layout_constraintEnd_toEndOf="parent"\n        app:layout_constraintBottom_toBottomOf="parent">\n\n        <com.nearbuy.nearbuymobile.view.NB_TextView\n            android:id="@+id/continueBookingCTA"\n            style="title_2_m"\n            android:layout_width="match_parent"\n            android:layout_height="wrap_content"\n            android:background="@drawable/bg_groupon_migration"\n            android:gravity="center"\n            android:paddingTop="10.3dp"\n            android:paddingBottom="10.3dp"\n            android:textColor="@color/white"\n            android:layout_marginTop="@dimen/dp_15"\n            android:layout_marginBottom="@dimen/dp_30"\n            android:layout_marginStart="@dimen/dp_15"\n            android:layout_marginEnd="@dimen/dp_15"\n            app:layout_constraintStart_toStartOf="parent"\n            app:layout_constraintEnd_toEndOf="parent"\n            app:layout_constraintTop_toTopOf="parent"\n            app:layout_constraintBottom_toBottomOf="parent"\n            tools:text="Continue Booking">\n\n        </com.nearbuy.nearbuymobile.view.NB_TextView>\n\n    </androidx.constraintlayout.widget.ConstraintLayout>\n\n</androidx.constraintlayout.motion.widget.MotionLayout>\n\n\n
Run Code Online (Sandbox Code Playgroud)\n\n

您看到 include 标签中的布局了吗?,这是布局 -

\n\n
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"\n    xmlns:aapt="http://schemas.android.com/aapt"\n    xmlns:app="http://schemas.android.com/apk/res-auto"\n    xmlns:tools="http://schemas.android.com/tools"\n    android:layout_width="match_parent"\n    android:layout_height="wrap_content"\n    android:background="#f7f7fd"\n    android:paddingLeft="@dimen/dp_15"\n    android:paddingTop="@dimen/dp_10"\n    android:paddingRight="@dimen/dp_15"\n    android:paddingBottom="@dimen/dp_15">\n\n    <com.nearbuy.nearbuymobile.view.NB_TextView\n        android:id="@+id/serviceName"\n        style="@style/body_1_m"\n        android:layout_width="wrap_content"\n        android:layout_height="wrap_content"\n        android:layout_marginTop="15dp"\n        android:textColor="@color/black_n"\n        app:layout_constraintStart_toStartOf="parent"\n        app:layout_constraintTop_toTopOf="parent"\n        tools:text="3 Seater Sofa Cleaning" />\n\n    <com.nearbuy.nearbuymobile.view.NB_TextView\n        android:id="@+id/mspText"\n        style="@style/display_3_b"\n        android:layout_width="wrap_content"\n        android:layout_height="wrap_content"\n        android:layout_marginTop="10dp"\n        android:textColor="@color/black_n"\n        app:layout_constraintEnd_toEndOf="parent"\n        app:layout_constraintTop_toTopOf="parent"\n        tools:text="\xe2\x82\xb9349" />\n\n    <com.nearbuy.nearbuymobile.view.NB_TextView\n        android:id="@+id/mrpText"\n        style="@style/body_4_r"\n        android:layout_width="wrap_content"\n        android:layout_height="wrap_content"\n        android:layout_marginTop="1.3dp"\n        android:textColor="@color/smoke"\n        app:layout_constraintEnd_toEndOf="@+id/mspText"\n        app:layout_constraintTop_toBottomOf="@+id/mspText"\n        app:strike="true"\n        tools:text="\xe2\x82\xb91,100" />\n\n    <com.nearbuy.nearbuymobile.view.NB_TextView\n        android:id

Kin*_*e59 5

你可以用以下方法修复它<Transition .... motion:layoutDuringTransition="honorRequest" >


hof*_*ord 1

MotionLayout 的工作原理是在起点和终点拍摄视图位置的快照(由 ConstraintSet 计算)。然后对所有变化的参数进行插值。一旦停止到开始或结束状态,它的操作类似于 ConstraintLayout。如果正在移动视图,则将调用一系列 .layout(t,b,l,r) (后跟绘制);如果正在调整视图大小,则将调用一系列的measure()、layout(),然后是draw()将被称为

开始和结束布局由 ConstraintSet 定义。理论上,您尝试做的事情是可能的,但很困难,并且需要一些其他调用。

如果想要创建一个简化版本并提交一个错误,包括 3 个主要文件(MainAcivity、layout 和 MotionScene)