android动画之旋转(rotate)

来源:互联网 发布:查看php fpm端口号 编辑:程序博客网 时间:2024/06/05 00:24

       今天看到android动画的知识点一时兴起就玩玩,没想到其中出了一点错,找了将近半小时才搞好大哭

不多说了上代码。

    首先要在res下建立anim文件夹然后在anim建立xxx.xml代码。

   rotate.xml如下:

             <?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <rotate
        android:interpolator="@android:anim/accelerate_interpolator"
        android:fromDegrees="0"
        android:toDegrees="360"
        android:pivotX="50%"
        android:pivotY="50%"
        android:duration="2000"
        android:repeatCount="5"
        android:repeatMode="restart"/>

</set>

    接下来我要说一说它们的属性:

   

  1.  fromDegrees   动画开始时的角度   
  2.   toDegrees     动画结束时物件的旋转角度,正代表顺时针     
  3.   pivotX    属性为动画相对于物件的X坐标的开始位置  
  4.   pivotY    属性为动画相对于物件的Y坐标的开始位置
  5.  duration  旋转一圈动画持续的时间
  6. repeatCount  动画重复的次数,如果为-1的话那么他会一直转下去
  7. repeatMode  这个就是动画结束后启动的模式
    然后就是layout代码:

   <ImageView
        android:layout_width="100px"
        android:layout_height="100px"
        android:id="@+id/imageView"
        android:src="@drawable/ic_launcher"/>

MainActivity.java

  

具体的就如上面的代码!

原创粉丝点击