Mih*_*aiV 6 android android-layout kotlin android-motionlayout
我的应用程序中有一个用于滑动过渡的 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>
Run Code Online (Sandbox Code Playgroud)
问题是在 alpha3 版本中,我可以使用这样的东西(并且它有效):
myMotionLayout.getConstraintSet(R.id.start)?.setGuidelinePercent(R.id.myGuideline, guidelinePercentage)
Run Code Online (Sandbox Code Playgroud)
现在我升级到2.0.0-alpha4,这不再有效,我不明白为什么。它始终采用 xml 中的默认值,并且在我尝试动态执行时永远不会更改。
我想要做的是根据一些动态数据(在 Fragment 的开头或用户返回时可用)更改过渡的起点。如果您对我如何使用 MotionLayout 实现这一点有更好的想法,请给我一个提示。
摇篮实现:
implementation "com.android.support.constraint:constraint-layout:2.0.0-alpha4"
Run Code Online (Sandbox Code Playgroud)
小智 1
我注意到 alpha4 版本中引入了类似的回归。通过反复试验以及以下错误报告,我能够将 ConstraintSet 更改以编程方式应用到 MotionLayout(beta1 版本)中。看来克隆方法不适用于 MotionLayout,而应该使用 getConstraintSet (正如您所做的那样)。看来您缺少的步骤是constraintSet.applyTo(motion_layout). 最后我还需要重新应用 MotionLayout 描述 xml。
实现“androidx.constraintlayout:constraintlayout:2.0.0-beta1”
脚步:
val constraintSet = motion_layout.getConstraintSet(R.id.motion_layout)
constraintSet.clear(R.id.txt_view, ConstraintSet.BOTTOM)
constraintSet.applyTo(motion_layout)
// If using a MotionLayout description xml file, re-apply it
motion_explore_article.loadLayoutDescription(R.xml.slide_over_image)
Run Code Online (Sandbox Code Playgroud)
错误报告: https://issuetracker.google.com/issues/131874827
| 归档时间: |
|
| 查看次数: |
1172 次 |
| 最近记录: |