Hoping to find out if it's possible to animate a layout orientation change. I am programmatically changing an LinearLayout orientation which contains a few views from vertical to horizontal and I don't think applying android:animateLayoutChanges="true" to the layout will automatically animate the change when the views move from being on top of each other to side by side. Is there any way to animate these changes using linearLayout.setOrientation(LinearLayout.HORIZONTAL) rather than something like an ObjectAnimator which causes more issues than it's worth in this situation? Thanks
Yes, you need to add this to your LinearLayout section as you mentioned.
android:animateLayoutChanges="true"
The default behavior for "animateLayoutChanges" will not animate LinearLayout orientation changes. To get that behavior you need to enable it with this:
val linearLayout = view.findViewById<LinearLayout>(R.id.my_linear_layout)
linearLayout.layoutTransition.enableTransitionType(LayoutTransition.CHANGING)
The details can be found here LayoutTransition Documentation, but the important piece is this:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With