gpt4 book ai didi

android - pivotX/Y 如何在旋转动画集中工作

转载 作者:行者123 更新时间:2023-11-29 17:01:40 24 4
gpt4 key购买 nike

我想了解旋转动画的工作原理。
通过以下内容,我按如下方式旋转 View :

<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="8000"
>

<rotate android:fromDegrees="0"
android:toDegrees="30"
android:pivotX="100%"
android:pivotY="100%"
/>

<rotate
android:toDegrees="100"
android:pivotX="100%"
android:pivotY="30%"
/>
</set>

结果:
enter image description here

现在我尝试以箭头为中心再次旋转箭头所在的位置。
所以我修改了我的动画集如下:

<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="8000">
<rotate android:fromDegrees="0"
android:toDegrees="30"
android:pivotX="100%"
android:pivotY="100%"
/>

<rotate
android:toDegrees="100"
android:pivotX="100%"
android:pivotY="30%"
/>

<rotate android:pivotY="-30%"
android:pivotX="40%"
android:toDegrees="100"/>
</set>

即我加了

<rotate android:pivotY="-30%"
android:pivotX="40%"
android:toDegrees="100"/>

这对我来说似乎是正确的,因为从屏幕上看,旋转点比最左边的 y 值小大约 30%,而 x 比最左边的 x 值大大约 40%。
但是当动画运行时它没有按预期工作。老实说,我不知道实际的旋转点是什么,整个 View 向左倾斜。
结果:

enter image description here

我在这里误解了什么?

最佳答案

Pivot 是它旋转所围绕的点(就像在照片中放置大头针)。如果你的“从”和“到”枢轴不一样,那么你不仅仅是在围绕一个设定点旋转,你在旋转一点,然后改变引脚位置并为每一步旋转更多一点(导致倾斜).

以防万一你不知道:Android coordinates从左上角而不是左下角开始。

我想你想要的只是

<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="8000">
<rotate android:fromDegrees="0"
android:toDegrees="130"
android:pivotX="100%"
android:pivotY="30%" />
<!-- I believe this, below will the the correct slide you need -->
<translate android:fromXDelta="0"
android:toXDelta="-100%" />
</set>

这将在 [100%, 30%] 处围绕引脚旋转 130 度(x 是最大值,即屏幕的右边缘,y 是屏幕下方的 30%)并且同时时间将它向右滑动,直到它位于起始位置右侧的 100%( View 宽度)

关于android - pivotX/Y 如何在旋转动画集中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42542043/

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