希望了解是否可以为布局方向更改设置动画。我正在以编程方式更改 LinearLayout 方向,其中包含一些从垂直到水平的 View ,我不认为将 android:animateLayoutChanges="true"应用于布局会在 View 从彼此重叠移动到并排。有没有什么方法可以使用 linearLayout.setOrientation(LinearLayout.HORIZONTAL) 而不是像 ObjectAnimator 这样的东西来为这些变化设置动画,在这种情况下,它会导致比它值得的更多的问题?谢谢
最佳答案
是的,您需要将其添加到您提到的 LinearLayout 部分。
android:animateLayoutChanges="true"
“animateLayoutChanges”的默认行为不会为 LinearLayout 方向变化设置动画。要获得该行为,您需要通过以下方式启用它:
val linearLayout = view.findViewById<LinearLayout>(R.id.my_linear_layout)
linearLayout.layoutTransition.enableTransitionType(LayoutTransition.CHANGING)
可以在这里找到详细信息 LayoutTransition Documentation ,但重要的是:
That is, all transition types besides CHANGING are enabled by default. You can also enable CHANGING animations by calling this method with the CHANGING transitionType.
关于android - Android 中的动 Canvas 局方向更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33377381/