gpt4 book ai didi

Android缩放动画: pivot doesn't work first time

转载 作者:太空宇宙 更新时间:2023-11-03 12:05:49 24 4
gpt4 key购买 nike

好吧,我的 ImageView 在 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>

问题是当动画第一次开始时,它从左上角开始缩放,而不是从中心开始。所有下一次它都工作得很好。有什么想法吗?

最佳答案

问题可能是在计算pivotXpivotY时引起的。

我必须在开始时将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 时,它根本不会被绘制,也无法计算宽度和高度。

关于Android缩放动画: pivot doesn't work first time,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31558331/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com