【问题标题】:Android View.rotation shrinks view slightlyAndroid View.rotation 略微缩小视图
【发布时间】:2022-10-14 10:07:44
【问题描述】:

当我使用

binding.testImage.rotation = 45f 

图像会旋转,但会略微缩小。我猜这是因为它试图保持视图的宽度和高度,并且当视图位于对角线时,宽度和高度会增加(因为对角线比宽度和高度长)。但是,我不确定。

当我像这样为视图设置动画时,这一点非常明显:

TransitionManager.beginDelayedTransition(rootView, transition)
binding.testImage.rotation = 90f 

这是过渡文件:

<?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>

这是布局:

<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>

这里发生的情况是,当 testImage 旋转时,它会在接近对角线(45 度)时收缩,然后在达到 90 度时增长。

【问题讨论】:

    标签: android animation


    【解决方案1】:

    我发现了问题。使用 Transition 时,动画对象会受到布局的影响,并且会影响依赖它的其他布局。使用 Animation 时,动画不受布局影响,也不会影响其他对象。

    我尝试寻找使用过渡的方法,但它无处可去,所以我改用了动画。希望这可以帮助遇到此问题的任何人。

    【讨论】:

      猜你喜欢
      • 2012-02-23
      • 2011-05-30
      • 1970-01-01
      • 1970-01-01
      • 2015-04-10
      • 1970-01-01
      • 2015-08-14
      • 1970-01-01
      • 2012-01-27
      相关资源
      最近更新 更多