【发布时间】:2019-04-17 07:29:31
【问题描述】:
我的应用中有一个用于滑动过渡的 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 实现这一点有更好的了解,请给我一个提示。
Gradle 实现:
implementation "com.android.support.constraint:constraint-layout:2.0.0-alpha4"
【问题讨论】:
-
我遇到了类似的问题:我正在尝试使用
val constraintSet = ConstraintSet() constraintSet.clone(motion_layout) constraintSet.clear(R.id.txt_view, ConstraintSet.BOTTOM) constraintSet.applyTo(motion_layout)以编程方式从 MotionLayout 中删除约束它使用 ConstraintLayout alpha 3,但从 alpha 4 到最新的 beta 停止工作1. 有趣的是,当我旋转设备时,会按预期进行约束移除。
标签: android android-layout kotlin android-motionlayout