开发者

Scale & translate animation in 2 steps

I need to make rather simple animation: ImageView should appear from left top corner to the center and then disappear in the top right corner. Here's my XML code. The problem is that ImageView goes back to top Left corner when I add second scale (minimizing). If I remove it then ImageView correctly moves to right side. What's wrong here?

<set>
    <scale
        andro开发者_运维百科id:fromXScale="0.0" 
        android:toXScale="1.0" 
        android:fromYScale="0.0" 
        android:toYScale="1.0" 
        android:pivotX="0"
        android:pivotY="0"
        android:duration="2000" />
    <translate
        android:duration="2000"
        android:fromXDelta="0"
        android:fromYDelta="0"          
        android:toXDelta="30%p"
        android:toYDelta="30%p" />
</set>          

<set>
    <translate
        android:startOffset="2000"
        android:duration="2000"
        android:fromXDelta="0%p"
        android:fromYDelta="0%p"            
        android:toXDelta="70%p"
        android:toYDelta="-25%p" />
    <scale 
        android:startOffset="2000"
        android:duration="2000"
        android:pivotX="0"
        android:pivotY="0"
        android:fromXScale="1.0" 
        android:toXScale="0.0" 
        android:fromYScale="1.0" 
        android:toYScale="0.0"  />
</set>


It looks like the sequence of animations in a set can affect their behavior.

I didn't modify any of your code, but only moved the 2nd translate behind the 2nd scale, and the animation worked as expected.

<set>
    <scale
        android:fromXScale="0.0"
        android:toXScale="1.0"
        android:fromYScale="0.0"
        android:toYScale="1.0"
        android:pivotX="0"
        android:pivotY="0"
        android:duration="2000" />
    <translate
        android:duration="2000"
        android:fromXDelta="0"
        android:fromYDelta="0"
        android:toXDelta="30%p"
        android:toYDelta="30%p" />
</set>

<set>
    <scale
        android:startOffset="2000"
        android:duration="2000"
        android:pivotX="0"
        android:pivotY="0"
        android:fromXScale="1.0"
        android:toXScale="0.0"
        android:fromYScale="1.0"
        android:toYScale="0.0"  />
    <translate
        android:startOffset="2000"
        android:duration="2000"
        android:fromXDelta="0%p"
        android:fromYDelta="0%p"
        android:toXDelta="70%p"
        android:toYDelta="-25%p" />
</set>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜