小编kau*_*v07的帖子

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 …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-motionlayout

5
推荐指数
2
解决办法
5485
查看次数