Android 缩放动画:枢轴第一次不起作用
Android scale animation: pivot doesn't work first time
好吧,我的图片视图在 RelativeLayout 中居中
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imgHomePlayPause"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:visibility="gone" />
我还有这个动画:
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale android:fromXScale="1.0"
android:fromYScale="1.0"
android:toXScale="2.0"
android:toYScale="2.0"
android:duration="400"
android:pivotX="50%"
android:pivotY="50%"/>
</set>
问题是当动画第一次开始时,它从左上角开始缩放,而不是从中心开始。所有下一次它都工作得很好。有什么想法吗?
问题可能是在计算 pivotX 和 pivotY 时引起的。
我必须将 View visibility 设置为 INVISIBLE 而不是 GONE开头。
这迫使我使用 RelativeLayout 因为我必须在两个 View.
之间切换
在您的情况下,只需将初始可见性更改为 不可见,如下所示:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imgHomePlayPause"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:visibility="invisible" />
动画首次启动后,您可以将可见性设置为 GONE,动画仍然有效。
结论:
我的想法是计算元素的宽度和高度只有绘制一次才能正确。
当元素可见性设置为 GONE 时,它根本不会被绘制,也无法计算宽度和高度。
好吧,我的图片视图在 RelativeLayout 中居中
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imgHomePlayPause"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:visibility="gone" />
我还有这个动画:
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale android:fromXScale="1.0"
android:fromYScale="1.0"
android:toXScale="2.0"
android:toYScale="2.0"
android:duration="400"
android:pivotX="50%"
android:pivotY="50%"/>
</set>
问题是当动画第一次开始时,它从左上角开始缩放,而不是从中心开始。所有下一次它都工作得很好。有什么想法吗?
问题可能是在计算 pivotX 和 pivotY 时引起的。
我必须将 View visibility 设置为 INVISIBLE 而不是 GONE开头。 这迫使我使用 RelativeLayout 因为我必须在两个 View.
之间切换在您的情况下,只需将初始可见性更改为 不可见,如下所示:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imgHomePlayPause"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:visibility="invisible" />
动画首次启动后,您可以将可见性设置为 GONE,动画仍然有效。
结论:
我的想法是计算元素的宽度和高度只有绘制一次才能正确。 当元素可见性设置为 GONE 时,它根本不会被绘制,也无法计算宽度和高度。