android - ConstraintLayout ConstraintSet 立即应用而不是动画
问题描述
我有以下布局:
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:id="@+id/rootLayout"
android:layout_height="match_parent">
<!-- ... -->
<View
android:id="@+id/fieldView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginStart="4dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="4dp"
android:elevation="6dp"
app:layout_constraintTop_toBottomOf="@id/topLayout" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/actionsLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:orientation="horizontal"
app:layout_constraintTop_toBottomOf="parent"
tools:layout_constraintTop_toBottomOf="@id/fieldView">
<!-- ... -->
我想actionsLayout
从屏幕底部(实际上是从屏幕外)滑动到fieldView
.
ConstraintSet()
.apply {
clone(context, R.layout.fragment_problem)
connect(R.id.actionsLayout, ConstraintSet.TOP, R.id.fieldView, ConstraintSet.BOTTOM)
}
.runAnimation(rootLayout, actionsLayoutAppearAnimationDuration, OvershootInterpolator())
runAnimation
资源:
fun ConstraintSet.runAnimation(rootLayout: ConstraintLayout, duration: Long, interpolator: Interpolator = LinearInterpolator()) {
val transition = AutoTransition()
.apply {
this.duration = duration
this.interpolator = interpolator
}
TransitionManager.beginDelayedTransition(rootLayout, transition)
this.applyTo(rootLayout)
}
注意:此扩展功能适用于其他布局。
但是在这个布局和这个动画上,它不会动画约束改变,而是立即应用它。所以,布局看起来和我预期的一样,除了动画——根本没有动画。为什么?
解决方案
看起来开始动画onViewCreated
并不是最好的主意。最简单的解决方案是在rootLayout.post()
.
推荐阅读
- angular - 如何在 Angular 中将 [(ngModel)] 与 FormGroup 一起使用
- java - 路径变量旁边的Spring Boot精确逗号
- c# - ASP.Net Core Blazor:如何根据标头值加载不同的 _Host.cshtml 文件
- r - 在“素食主义者”中排列网络(作为邻接矩阵) - 我如何获取网络统计信息?
- oracle - Flyway 是否支持 kerberos 身份验证?
- powershell - 从对象字符串中获取值以存储在属性内部
- python - 如何避免 conda activate base 在我的 VS Code 编辑器中自动执行?
- python - Python从url解析JSON不完整
- javascript - 通过正文中的 fetch() 发送 GET 数据,而不是在 URL 中指定它
- powerbi - DAX:如何在日期过滤的视觉对象上使用 TOTALYTD 度量?