Android动画:如何旋转一个视图并在旋转后将其冻结

6
我刚接触Android动画,想做一个基本的动画。
  1. Rotate a view by 180deg

    <set xmlns:android="http://schemas.android.com/apk/res/android">
    <rotate
        android:fromDegrees="0"
        android:toDegrees="180"
        android:pivotX="50%"
        android:pivotY="50%"
        android:duration="300"
        android:fillAfter="true"
        android:fillEnabled="true"
         />
    

但问题是动画完成后,视图会返回到其原始位置。我希望在动画完成后将视图旋转180度。

我还添加了一个带有onAnimationEnd的AnimationListener来实现它,但它会出现一些故障。


1
在动画结束时,设置您的视图的“旋转”属性。 - Yugesh
@Yugesh 我尝试使用onAnimationEnd来旋转视图,但是在一瞬间它会显示视图的原始位置,然后应用旋转变化。 - inni
你能帮我处理一下这段代码吗? - inni
1个回答

6

嘿,使用这个……

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true"
    android:fillEnabled="true">

<rotate
    android:duration="1000"
    android:fromDegrees="0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toDegrees="180" />

 </set>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接