android - Android 中的动 Canvas 局方向更改

标签 android animation orientation transitions

希望了解是否可以为布局方向更改设置动画。我正在以编程方式更改 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/

相关文章:

ios - shouldAutorotateToInterfaceOrientation 没有被调用

android - 在 Android 上使用 OpenCV 预处理图像以优化 ocr 准确性

android - java.lang.NoClassDefFoundError : oauth. signpost.commonshttp.CommonsHttpOAuthConsumer android

css - IE11 中的动画背景图像

swift - CAAnimation 路径仅在 View /图层的范围内

android - 如何将 MediaRecorder 方向设置为横向或纵向

java - 实现示例代码以使用 OAuth2 对 Gmail 进行身份验证

java - 将ScrollView插入布局

css - 为什么这个动画不正确?

android - 锁定屏幕方向 (Android)