ivotX/Y如何在旋转动画集中工作 [英] How does pivotX/Y work in a rotate animation set

查看:111
本文介绍了ivotX/Y如何在旋转动画集中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解旋转动画的工作原理.
通过以下操作,我将视图旋转如下:

I am trying to understand how rotate animation works.
With the following I rotate a view as follows:

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

结果:

现在,我正尝试以箭头为中心再次旋转箭头.
因此,我修改了动画集,如下所示:

Now where the arrow is I am trying to rotate again using that as a center.
So I modified my animation set as follows:

<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%左右.
但是,当动画运行时,它无法按预期运行.老实说,我不知道实际的旋转点是什么,整个视图向左倾斜.
结果:

This seems correct to me because looking at the screen the rotate point is around 30% less than the left most value of y and x is about 40% more than the left most value of x.
But when the animation runs it is not working as expected. To be honest I have no clue what is the actual rotation point and the whole view skews to the left.
Result:

我在这里误解了什么?

What am I misunderstanding here?

推荐答案

枢轴是旋转点(例如,将销钉插入照片中).如果您的从"和到"枢轴不同,那么您不仅要绕设定点旋转,还需要旋转一点,然后更改销钉的位置,并在每一步中再旋转一点(导致偏斜). ).

Pivot is the point around which it rotates (like putting a pin in a photo). If your 'from' and 'to' pivots aren't the same then you are not just rotating around a set point, you're rotating a bit, then changing the pins location and rotating a bit more for each step (causing a skew).

以防万一,您可能不知道: Android坐标开始于左上方而不是左下方.

Just in case you don't know: Android coordinates start at top left not bottom left.

我想你想要的就是这个

<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%](x是最大值,即屏幕的右边缘,y是屏幕下方的30%)的角度围绕销旋转130度.时间将其向右滑动,直到其到达起始位置右侧的100%(视图宽度)

Which will rotate it 130 degrees around the pin at [100%, 30%] (x being the maximum value , i.e right edge of the screen, and y being 30% of the way down the screen) and at the same time slide it right until it's 100% (of view width) to the right of it's starting position

这篇关于ivotX/Y如何在旋转动画集中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆