gpt4 book ai didi

android - constraintlayout.widget.Group 动画不适用于 TransitionManager

转载 作者:行者123 更新时间:2023-12-03 19:44:36 32 4
gpt4 key购买 nike

有人知道为什么要制作动画constraintlayout.widget.Group TransitionManager 的可见性不起作用?这个小部件不是为这些东西制作的吗?

如果在将 View 与组 分离后隐藏或显示项目,则它正在工作

        <androidx.constraintlayout.widget.Group
android:id="@+id/cardHeadersGroup"
android:layout_width="0dp"
android:layout_height="0dp"
android:visibility="invisible"
app:constraint_referenced_ids="cardSystemHeader,cardSimpleHeader,cardCombinedHeader"
app:layout_constraintBottom_toBottomOf="@+id/cardCombinedHeader"
app:layout_constraintEnd_toEndOf="@+id/cardSystemHeader"
app:layout_constraintStart_toStartOf="@+id/cardSimpleHeader"
app:layout_constraintTop_toTopOf="parent"
tools:visibility="visible"/>
 val headersGroup = binding.cardHeadersGroup

val slideIn = Slide()
slideIn.slideEdge = Gravity.BOTTOM
slideIn.mode = Slide.MODE_IN
slideIn.addTarget(headersGroup)

TransitionManager.beginDelayedTransition(binding.root as ViewGroup, slideIn)

headersGroup.visibility = VISIBLE

最佳答案

我最近一直在使用 TransitionManagerConstraintLayout.Group并发现它非常有问题。

最终我决定转储整个 ConstraintLayout.Group并创建了一个代码内 AnimationGroup (类似于 in-xml ConstraintLayout.Group ):

class AnimationGroup(vararg val views: View) {
var visibility: Int = View.INVISIBLE
set(value) {
views.forEach { it.visibility = value }
field = value
}
}

Transition 的扩展功能:
private fun Transition.addTarget(animationGroup: AnimationGroup) {
animationGroup.views.forEach { viewInGroup -> this.addTarget(viewInGroup) }
}

这样,您可以执行以下操作(几乎完全相同的代码,但更简单的 xml - 没有 ConstraintLayout.Group ):
val headersGroup = AnimationGroup(
binding.cardSystemHeader,
binding.cardSimpleHeader,
binding.cardCombinedHeader
)

val slideIn = Slide()
slideIn.slideEdge = Gravity.BOTTOM
slideIn.mode = Slide.MODE_IN
slideIn.addTarget(headersGroup)

TransitionManager.beginDelayedTransition(binding.root as ViewGroup, slideIn)

headersGroup.visibility = VISIBLE

关于android - constraintlayout.widget.Group 动画不适用于 TransitionManager,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56769395/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com