我的应用中有一个用于滑动过渡的 MotionLayout。目前我刚刚更新2.0.0-alpha3
到2.0.0-alpha4
发布,有些事情不像以前那样工作。有“myView”,这是一个应该从屏幕底部扩展到标题视图的布局。它对我需要以编程方式控制的指南有一个限制(基于一些用户操作)。
代码中没有其他更改,因此降级到 alpha3 使一切按预期工作。
代码非常基本:
<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"
motion:interpolator="linear">
<!-- I used motion:motionInterpolator="linear" for alpha4-->
<OnSwipe
motion:dragDirection="dragUp"
motion:touchAnchorId="@id/myView"
motion:touchAnchorSide="top" />
</Transition>
<ConstraintSet android:id="@+id/start">
<Constraint
android:id="@id/myView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="@id/myGuideline" />
</ConstraintSet>
<ConstraintSet android:id="@+id/end">
<Constraint
android:id="@id/myView"
android:layout_width="match_parent"
android:layout_height="0dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toBottomOf="@id/someHeaderView" />
</ConstraintSet>
</MotionScene>
问题是在 alpha3 版本中,我可以使用这样的东西(并且它有效):
myMotionLayout.getConstraintSet(R.id.start)?.setGuidelinePercent(R.id.myGuideline, guidelinePercentage)
现在我升级到2.0.0-alpha4
,这不再起作用,我不明白为什么。它总是从 xml 中获取默认值,并且在我尝试动态执行时永远不会更改。
我要做的是根据一些动态数据(在片段开头或用户返回时可用)更改过渡的起点。如果您对如何使用 MotionLayout 实现这一点有更好的了解,请给我一个提示。
摇篮实现:
implementation "com.android.support.constraint:constraint-layout:2.0.0-alpha4"