本文介绍了带有垂直ScrollView的MotionLayout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用运动布局制作动画,并想将scrollView设置为onSwipe Transition上的运动场景的targetAnchor,但是它不起作用.也许我对onSwipe转换一无所知.
I'm trying to make animation with motion layout, and want to set scrollView as targetAnchor for motion scene onSwipe Transition, but it doesn't work.Maybe I don't know some thing about onSwipe transition.
这是我的布局文件
<androidx.constraintlayout.motion.widget.MotionLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/main_background_color"
app:layoutDescription="@xml/base_scroll_scene">
<ImageView
android:id="@+id/background_image"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="@dimen/scrollable_background_image_margin_bottom"
android:scaleType="centerCrop"
android:src="@drawable/lift_bg"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="@dimen/top_gradient_mask_height"
android:background="@drawable/top_gradient_mask"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/ski_more_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/ski_more_logo_margin_top"
android:src="@drawable/ic_skimore_logo"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/locked_icon"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginTop="@dimen/locked_icon_margin_top"
android:src="@drawable/ic_lock"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/ski_more_logo" />
<FrameLayout
android:id="@+id/bottom_gradient_mask"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="@drawable/bottom_gradient_mask"
app:layout_constraintBottom_toBottomOf="@+id/background_image" />
<ScrollView
android:id="@+id/content_scroll_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:overScrollMode="never"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent">
<FrameLayout
android:id="@+id/content_container_view"
android:layout_width="match_parent"
android:clickable="false"
android:layout_height="match_parent" />
</ScrollView>
</androidx.constraintlayout.motion.widget.MotionLayout>
在滚动视图中,我以编程方式添加了一些高度较大的内容,这些内容将可以滚动.
In scroll view programmatically i'm adding some content with big height, which will be scrollable.
这是我的动作场景
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:motion="http://schemas.android.com/apk/res-auto">
<Transition
motion:constraintSetEnd="@+id/end"
motion:constraintSetStart="@+id/start"
motion:duration="1000">
<OnSwipe
motion:dragDirection="dragUp"
motion:touchAnchorId="@+id/content_scroll_view"
motion:touchAnchorSide="top" />
</Transition>
<ConstraintSet android:id="@+id/start"/>
<ConstraintSet android:id="@+id/end">
<Constraint
android:id="@+id/background_image"
android:layout_width="0dp"
android:layout_height="@dimen/top_gradient_mask_height"
android:layout_marginBottom="@dimen/scrollable_background_image_margin_bottom"
android:scaleType="centerCrop"
android:src="@drawable/lift_bg"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="parent" />
</ConstraintSet>
</MotionScene>
请帮助我,谢谢.
推荐答案
您是否尝试将ScrollView
替换为NestedScrollView
?
而且,我还将定义ConstraintSet
开始".
And, also, I would define ConstraintSet
"start" as well.
这篇关于带有垂直ScrollView的MotionLayout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!