When I am using
binding.testImage.rotation = 45f
the image rotates, but it shrinks slightly. I am guessing this is because its trying to keep the width and height of the view, and when the view is at a diagonal, the width and height grows (as the diagonal is longer than the width and height). However, I am not sure.
This is very visible when I am animating the view like so:
TransitionManager.beginDelayedTransition(rootView, transition)
binding.testImage.rotation = 90f
Here is the transition file:
<?xml version="1.0" encoding="UTF-8"?>
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android">
<changeTransform
android:duration="1000"
android:startDelay="1000"/>
</transitionSet>
Here is the layout:
<LinearLayout
android:layout_width="200dp"
android:layout_height="200dp"
app:layout_constraintBottom_toTopOf="@id/closeit"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:gravity="center"
android:background="@color/blue">
<ImageView
android:id="@ id/testImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/test"
android:scaleType="centerCrop"
android:visibility="visible"/>
</LinearLayout>
What happens here, is as the testImage rotates it shrinks as it approaches the diagonal (45 degrees) then grows as it reaches the 90 degrees.
CodePudding user response:
I found the problem. When using a Transition, the animated object is affected by layout and will affect other layouts that depend on it. When using an Animation, the animation is not affected by layout and doesn't affect other objects.
I tried finding ways of using Transition, but it was not going anywhere, so I used Animation instead. Hopefully this helps anyone who runs into this.