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

Android 正在进行MotionLayout时视图操纵不起作用,android,android-layout,android-motionlayout,Android,Android Layout,Android Motionlayout,我正在尝试创建一个布局,其中视图将向上滚动,但在视图中有一个组件不应从视图中滚动出来,并固定在顶部,其余内容将滚动到其下方,该组件将滚动到屏幕顶部 因此,对于停靠部分,我使用了运动布局,在结束状态下,它被约束到父对象的顶部。我在停靠组件之后放置了一个嵌套的scrollview。这是我的运动场景文件- <Transition android:id="@+id/scrollTransition" motion:constraintSetEnd="@+id/end" mo

我正在尝试创建一个布局,其中视图将向上滚动,但在视图中有一个组件不应从视图中滚动出来,并固定在顶部,其余内容将滚动到其下方,该组件将滚动到屏幕顶部

因此,对于停靠部分,我使用了运动布局,在结束状态下,它被约束到父对象的顶部。我在停靠组件之后放置了一个嵌套的scrollview。这是我的运动场景文件-

<Transition
    android:id="@+id/scrollTransition"
    motion:constraintSetEnd="@+id/end"
    motion:constraintSetStart="@id/start"
    motion:duration="1000">
   <KeyFrameSet>
   </KeyFrameSet>
    <OnSwipe
        motion:dragDirection="dragUp"
        motion:onTouchUp="stop"
        motion:touchAnchorId="@id/merchant_details"
        motion:moveWhenScrollAtTop="true"/>
</Transition>

<ConstraintSet android:id="@+id/start">

</ConstraintSet>

<ConstraintSet android:id="@+id/end">
    <Constraint
        android:layout_height="wrap_content"
        motion:layout_constraintStart_toStartOf="parent"
        motion:layout_constraintEnd_toEndOf="parent"
        motion:layout_constraintBottom_toTopOf="@id/merchant_details"
        android:layout_width="match_parent"
        android:id="@+id/product_details" />
    <Constraint
        android:layout_height="wrap_content"
        motion:layout_constraintStart_toStartOf="parent"
        motion:layout_constraintEnd_toEndOf="parent"
        motion:layout_constraintTop_toTopOf="parent"
        android:layout_width="match_parent"
        android:id="@+id/merchant_details" />
</ConstraintSet>
是否在include标记中看到布局,这是布局图-

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:aapt="http://schemas.android.com/aapt"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#f7f7fd"
    android:paddingLeft="@dimen/dp_15"
    android:paddingTop="@dimen/dp_10"
    android:paddingRight="@dimen/dp_15"
    android:paddingBottom="@dimen/dp_15">

    <com.nearbuy.nearbuymobile.view.NB_TextView
        android:id="@+id/serviceName"
        style="@style/body_1_m"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="15dp"
        android:textColor="@color/black_n"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:text="3 Seater Sofa Cleaning" />

    <com.nearbuy.nearbuymobile.view.NB_TextView
        android:id="@+id/mspText"
        style="@style/display_3_b"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:textColor="@color/black_n"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:text="₹349" />

    <com.nearbuy.nearbuymobile.view.NB_TextView
        android:id="@+id/mrpText"
        style="@style/body_4_r"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="1.3dp"
        android:textColor="@color/smoke"
        app:layout_constraintEnd_toEndOf="@+id/mspText"
        app:layout_constraintTop_toBottomOf="@+id/mspText"
        app:strike="true"
        tools:text="₹1,100" />

    <com.nearbuy.nearbuymobile.view.NB_TextView
        android:id="@+id/discountText"
        style="@style/body_2_m"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="1.3dp"
        android:layout_marginEnd="6.7dp"
        android:textColor="#ff0000"
        app:layout_constraintBottom_toBottomOf="@+id/mrpText"
        app:layout_constraintEnd_toStartOf="@+id/mrpText"
        app:layout_constraintTop_toBottomOf="@+id/mspText"
        tools:text="55% OFF" />

    <LinearLayout
        android:id="@+id/timeAndInfoLayout"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="20dp"
        android:orientation="vertical"
        app:layout_constraintEnd_toStartOf="@+id/discountText"
        app:layout_constraintStart_toStartOf="@+id/serviceName"
        app:layout_constraintTop_toBottomOf="@+id/serviceName" />

    <com.nearbuy.nearbuymobile.view.NB_TextView
        android:id="@+id/freeCancellationText"
        style="@style/body_3_m"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="3dp"
        android:textColor="#1bbb33"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/timeAndInfoLayout"
        tools:text="Free Cancellation" />

    <ImageView
        android:id="@+id/freeCancellationIcon"
        android:layout_width="@dimen/dp_16"
        android:layout_height="@dimen/dp_16"
        android:layout_marginStart="10dp"
        app:layout_constraintBottom_toBottomOf="@+id/freeCancellationText"
        app:layout_constraintStart_toEndOf="@+id/freeCancellationText"
        app:layout_constraintTop_toTopOf="@+id/freeCancellationText"
        app:srcCompat="@drawable/info_green" />

    <androidx.constraintlayout.widget.Barrier
        android:id="@+id/dividerBarrier"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:barrierDirection="bottom"
        app:constraint_referenced_ids="timeAndInfoLayout,discountText,freeCancellationText,serviceName,freeCancellationIcon,mspText,mrpText"
        tools:layout_editor_absoluteX="15dp"
        tools:layout_editor_absoluteY="658dp" />

    <View
        android:id="@+id/divider9"
        android:layout_width="0dp"
        android:layout_height="1dp"
        android:layout_marginTop="10dp"
        android:background="#d7dff0"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@id/dividerBarrier" />

    <com.nearbuy.nearbuymobile.view.NB_TextView
        android:id="@+id/merchantNameTitle"
        style="@style/small_r"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:textColor="@color/black_n"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/divider9"
        tools:text="Service provided by" />

    <RelativeLayout
        android:id="@+id/merchantRatingLayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="7dp"
        android:padding="@dimen/dp_4"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/merchantNameTitle">

        <aapt:attr name="android:background">

            <shape android:shape="rectangle">

                <corners android:radius="3dp" />

                <solid android:color="#1bbb33" />
            </shape>

        </aapt:attr>

        <com.nearbuy.nearbuymobile.view.NB_TextView
            android:id="@+id/merchantRatingText"
            style="@style/body_3_m"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/white"
            tools:text="4.5" />

        <ImageView
            android:id="@+id/merchantRatingIcon"
            android:layout_width="@dimen/dp_10"
            android:layout_height="@dimen/dp_10"
            android:layout_centerVertical="true"
            android:layout_marginLeft="2.7dp"
            android:layout_toRightOf="@id/merchantRatingText"
            app:srcCompat="@drawable/hs_merchant_rating_star" />

    </RelativeLayout>

    <com.nearbuy.nearbuymobile.view.NB_TextView
        android:id="@+id/merchantName"
        style="@style/body_2_r"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="10dp"
        android:layout_marginEnd="20dp"
        android:textColor="@color/black_n"
        app:layout_constraintBottom_toBottomOf="@+id/merchantRatingLayout"
        app:layout_constraintEnd_toStartOf="@+id/changeMerchantCTA"
        app:layout_constraintStart_toEndOf="@+id/merchantRatingLayout"
        app:layout_constraintTop_toTopOf="@+id/merchantRatingLayout"
        tools:text="Balaji Deep Cleaning" />

    <com.nearbuy.nearbuymobile.view.NB_TextView
        android:id="@+id/otherProviderTitle"
        style="@style/small_r"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:textColor="@color/black_n"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/divider9"
        tools:text="Other Providers available" />

    <com.nearbuy.nearbuymobile.view.NB_TextView
        android:id="@+id/changeMerchantCTA"
        style="@style/body_2_b"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="9dp"
        android:gravity="end"
        android:textColor="@color/delight"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/otherProviderTitle"
        tools:text="Change (3 Available)" />
现在,每当我在两个州之间停下来,试图操纵视图时,就像有一个按钮,点击按钮会弹出一张底页,我选择另一个商户,而现在当操纵布局时,它不会显示任何内容。。就这样消失了,一旦我适应了任何一种状态,一切都会运转起来。像这样-

完整的视频在这里-


我不明白这个问题,有人能告诉我为什么会这样吗?以及如何解决此问题。

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

开始和结束布局由约束集定义。 从理论上讲,你正在尝试做的是可能的,但很困难,需要一些其他的电话


如果想要创建一个简化版本并归档一个bug,其中包括3个主要文件Mainacity、layout&motionScene

您可以使用

修复它,我使用layout inspector进行了调试,它似乎正在进行中,我膨胀了一些视图以添加到该布局中,膨胀视图的高度为0,而不是包裹内容,但一旦进入状态或滚动开始,它就会获得适当的高度。知道为什么会发生这种情况吗?是的,我的意思是这应该是可能的,我尝试在我正在更改的视图上使用requestLayout,并尝试使视图无效,以便再次绘制,但这也不起作用,在我看来,这是一个有效的用例,如果我们不能在其进行过程中操纵或更改视图,那么对于许多开发人员和许多用例来说,这将是一个问题,我将创建一个简化的版本并提交一个bug,希望他们能发现它。。
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:aapt="http://schemas.android.com/aapt"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#f7f7fd"
    android:paddingLeft="@dimen/dp_15"
    android:paddingTop="@dimen/dp_10"
    android:paddingRight="@dimen/dp_15"
    android:paddingBottom="@dimen/dp_15">

    <com.nearbuy.nearbuymobile.view.NB_TextView
        android:id="@+id/serviceName"
        style="@style/body_1_m"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="15dp"
        android:textColor="@color/black_n"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:text="3 Seater Sofa Cleaning" />

    <com.nearbuy.nearbuymobile.view.NB_TextView
        android:id="@+id/mspText"
        style="@style/display_3_b"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:textColor="@color/black_n"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:text="₹349" />

    <com.nearbuy.nearbuymobile.view.NB_TextView
        android:id="@+id/mrpText"
        style="@style/body_4_r"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="1.3dp"
        android:textColor="@color/smoke"
        app:layout_constraintEnd_toEndOf="@+id/mspText"
        app:layout_constraintTop_toBottomOf="@+id/mspText"
        app:strike="true"
        tools:text="₹1,100" />

    <com.nearbuy.nearbuymobile.view.NB_TextView
        android:id="@+id/discountText"
        style="@style/body_2_m"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="1.3dp"
        android:layout_marginEnd="6.7dp"
        android:textColor="#ff0000"
        app:layout_constraintBottom_toBottomOf="@+id/mrpText"
        app:layout_constraintEnd_toStartOf="@+id/mrpText"
        app:layout_constraintTop_toBottomOf="@+id/mspText"
        tools:text="55% OFF" />

    <LinearLayout
        android:id="@+id/timeAndInfoLayout"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="20dp"
        android:orientation="vertical"
        app:layout_constraintEnd_toStartOf="@+id/discountText"
        app:layout_constraintStart_toStartOf="@+id/serviceName"
        app:layout_constraintTop_toBottomOf="@+id/serviceName" />

    <com.nearbuy.nearbuymobile.view.NB_TextView
        android:id="@+id/freeCancellationText"
        style="@style/body_3_m"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="3dp"
        android:textColor="#1bbb33"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/timeAndInfoLayout"
        tools:text="Free Cancellation" />

    <ImageView
        android:id="@+id/freeCancellationIcon"
        android:layout_width="@dimen/dp_16"
        android:layout_height="@dimen/dp_16"
        android:layout_marginStart="10dp"
        app:layout_constraintBottom_toBottomOf="@+id/freeCancellationText"
        app:layout_constraintStart_toEndOf="@+id/freeCancellationText"
        app:layout_constraintTop_toTopOf="@+id/freeCancellationText"
        app:srcCompat="@drawable/info_green" />

    <androidx.constraintlayout.widget.Barrier
        android:id="@+id/dividerBarrier"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:barrierDirection="bottom"
        app:constraint_referenced_ids="timeAndInfoLayout,discountText,freeCancellationText,serviceName,freeCancellationIcon,mspText,mrpText"
        tools:layout_editor_absoluteX="15dp"
        tools:layout_editor_absoluteY="658dp" />

    <View
        android:id="@+id/divider9"
        android:layout_width="0dp"
        android:layout_height="1dp"
        android:layout_marginTop="10dp"
        android:background="#d7dff0"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@id/dividerBarrier" />

    <com.nearbuy.nearbuymobile.view.NB_TextView
        android:id="@+id/merchantNameTitle"
        style="@style/small_r"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:textColor="@color/black_n"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/divider9"
        tools:text="Service provided by" />

    <RelativeLayout
        android:id="@+id/merchantRatingLayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="7dp"
        android:padding="@dimen/dp_4"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/merchantNameTitle">

        <aapt:attr name="android:background">

            <shape android:shape="rectangle">

                <corners android:radius="3dp" />

                <solid android:color="#1bbb33" />
            </shape>

        </aapt:attr>

        <com.nearbuy.nearbuymobile.view.NB_TextView
            android:id="@+id/merchantRatingText"
            style="@style/body_3_m"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/white"
            tools:text="4.5" />

        <ImageView
            android:id="@+id/merchantRatingIcon"
            android:layout_width="@dimen/dp_10"
            android:layout_height="@dimen/dp_10"
            android:layout_centerVertical="true"
            android:layout_marginLeft="2.7dp"
            android:layout_toRightOf="@id/merchantRatingText"
            app:srcCompat="@drawable/hs_merchant_rating_star" />

    </RelativeLayout>

    <com.nearbuy.nearbuymobile.view.NB_TextView
        android:id="@+id/merchantName"
        style="@style/body_2_r"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="10dp"
        android:layout_marginEnd="20dp"
        android:textColor="@color/black_n"
        app:layout_constraintBottom_toBottomOf="@+id/merchantRatingLayout"
        app:layout_constraintEnd_toStartOf="@+id/changeMerchantCTA"
        app:layout_constraintStart_toEndOf="@+id/merchantRatingLayout"
        app:layout_constraintTop_toTopOf="@+id/merchantRatingLayout"
        tools:text="Balaji Deep Cleaning" />

    <com.nearbuy.nearbuymobile.view.NB_TextView
        android:id="@+id/otherProviderTitle"
        style="@style/small_r"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:textColor="@color/black_n"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/divider9"
        tools:text="Other Providers available" />

    <com.nearbuy.nearbuymobile.view.NB_TextView
        android:id="@+id/changeMerchantCTA"
        style="@style/body_2_b"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="9dp"
        android:gravity="end"
        android:textColor="@color/delight"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/otherProviderTitle"
        tools:text="Change (3 Available)" />